Patchwork Go patch committed: Don't crash on type descriptor of abstract type

login
register
mail settings
Submitter Ian Taylor
Date March 3, 2011, 4:25 a.m.
Message ID <mcrlj0w3k4x.fsf@google.com>
Download mbox | patch
Permalink /patch/85225/
State New
Headers show

Comments

Ian Taylor - March 3, 2011, 4:25 a.m.
It's possible for erroneous code to attempt to get a type descriptor of
an abstract type.  This patch to the Go frontend avoids crashing when
that happens.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 61c84c273f21 go/types.cc
--- a/go/types.cc	Wed Mar 02 19:30:37 2011 -0800
+++ b/go/types.cc	Wed Mar 02 19:57:21 2011 -0800
@@ -1764,7 +1764,12 @@ 
 tree
 Integer_type::do_get_tree(Gogo*)
 {
-  gcc_assert(!this->is_abstract_);
+  if (this->is_abstract_)
+    {
+      gcc_assert(saw_errors());
+      return error_mark_node;
+    }
+
   if (this->is_unsigned_)
     {
       if (this->bits_ == INT_TYPE_SIZE)
@@ -1818,7 +1823,7 @@ 
 void
 Integer_type::do_reflection(Gogo*, std::string*) const
 {
-  gcc_unreachable();
+  gcc_assert(saw_errors());
 }
 
 // Mangled name.
@@ -1974,7 +1979,7 @@ 
 void
 Float_type::do_reflection(Gogo*, std::string*) const
 {
-  gcc_unreachable();
+  gcc_assert(saw_errors());
 }
 
 // Mangled name.
@@ -2134,7 +2139,7 @@ 
 void
 Complex_type::do_reflection(Gogo*, std::string*) const
 {
-  gcc_unreachable();
+  gcc_assert(saw_errors());
 }
 
 // Mangled name.