Patchwork Go patch committed: Don't crash indexing into erroneous array

login
register
mail settings
Submitter Ian Taylor
Date Dec. 21, 2010, 10:58 p.m.
Message ID <mcrei9alolz.fsf@google.com>
Download mbox | patch
Permalink /patch/76340/
State New
Headers show

Comments

Ian Taylor - Dec. 21, 2010, 10:58 p.m.
This patch fixes the Go compiler to not crash when indexing into an
erroneous array.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 4942fa9d5d0e go/expressions.cc
--- a/go/expressions.cc	Tue Dec 21 14:54:39 2010 -0800
+++ b/go/expressions.cc	Tue Dec 21 14:56:49 2010 -0800
@@ -9154,7 +9154,11 @@ 
   source_location loc = this->location();
 
   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 error_mark_node;
+    }
 
   tree type_tree = array_type->get_tree(gogo);
   if (type_tree == error_mark_node)