Patchwork Go patch committed: Don't crash on invalid slice composite literal

login
register
mail settings
Submitter Ian Taylor
Date Dec. 14, 2010, 11:56 p.m.
Message ID <mcrd3p37vu4.fsf@google.com>
Download mbox | patch
Permalink /patch/75588/
State New
Headers show

Comments

Ian Taylor - Dec. 14, 2010, 11:56 p.m.
This patch to the Go frontend avoids crashing when building an invalid
slice composite literal.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 78d78fa04fac go/expressions.cc
--- a/go/expressions.cc	Tue Dec 14 15:45:04 2010 -0800
+++ b/go/expressions.cc	Tue Dec 14 15:49:13 2010 -0800
@@ -10709,6 +10709,9 @@ 
 {
   Type* element_type = this->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;
+
   tree values;
   tree length_tree;
   if (this->vals() == NULL || this->vals()->empty())
@@ -10792,6 +10795,8 @@ 
   // Build a constructor for the open array.
 
   tree type_tree = this->type()->get_tree(context->gogo());
+  if (type_tree == error_mark_node)
+    return error_mark_node;
   gcc_assert(TREE_CODE(type_tree) == RECORD_TYPE);
 
   VEC(constructor_elt,gc)* init = VEC_alloc(constructor_elt, gc, 3);
@@ -10815,6 +10820,8 @@ 
   elt->value = fold_convert(TREE_TYPE(field), length_tree);
 
   tree constructor = build_constructor(type_tree, init);
+  if (constructor == error_mark_node)
+    return error_mark_node;
   if (!is_in_function && is_constant_initializer)
     TREE_CONSTANT(constructor) = 1;