Patchwork Go patch committed: Don't crash if array length is invalid const

login
register
mail settings
Submitter Ian Taylor
Date Dec. 22, 2010, 3:25 p.m.
Message ID <mcrzkrxhlso.fsf@google.com>
Download mbox | patch
Permalink /patch/76422/
State New
Headers show

Comments

Ian Taylor - Dec. 22, 2010, 3:25 p.m.
This patch to the Go frontend avoids a crash if the length of an array
is a const which turns out to be invalid.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 08ce2cd2cdcd go/expressions.cc
--- a/go/expressions.cc	Wed Dec 22 07:08:44 2010 -0800
+++ b/go/expressions.cc	Wed Dec 22 07:21:09 2010 -0800
@@ -9095,7 +9095,11 @@ 
     this->report_error(_("slice end must be integer"));
 
   Array_type* array_type = this->array_->type()->array_type();
-  gcc_assert(array_type != NULL);
+  if (array_type == NULL)
+    {
+      gcc_assert(this->array_->type()->is_error_type());
+      return;
+    }
 
   unsigned int int_bits =
     Type::lookup_integer_type("int")->integer_type()->bits();
@@ -10936,7 +10940,14 @@ 
 tree
 Open_array_construction_expression::do_get_tree(Translate_context* context)
 {
-  Type* element_type = this->type()->array_type()->element_type();
+  Array_type* array_type = this->type()->array_type();
+  if (array_type == NULL)
+    {
+      gcc_assert(this->type()->is_error_type());
+      return error_mark_node;
+    }
+
+  Type* element_type = array_type->element_type();
   tree element_type_tree = element_type->get_tree(context->gogo());
   if (element_type_tree == error_mark_node)
     return error_mark_node;