Patchwork Go patch committed: Don't crash on erroneous void temp initializer

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

Comments

Ian Taylor - March 3, 2011, 1:39 a.m.
Sometimes an erroneous initializer of a temporary statement can have a
void type, which leads to a crash creating a temporary variable.  This
patch fixes the crash by checking for an erroneous initialier earlier.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 0710ec20ce0d go/statements.cc
--- a/go/statements.cc	Wed Mar 02 17:16:25 2011 -0800
+++ b/go/statements.cc	Wed Mar 02 17:33:20 2011 -0800
@@ -391,7 +391,10 @@ 
 {
   gcc_assert(this->decl_ == NULL_TREE);
   tree type_tree = this->type()->get_tree(context->gogo());
-  if (type_tree == error_mark_node)
+  tree init_tree = (this->init_ == NULL
+		    ? NULL_TREE
+		    : this->init_->get_tree(context));
+  if (type_tree == error_mark_node || init_tree == error_mark_node)
     {
       this->decl_ = error_mark_node;
       return error_mark_node;
@@ -423,11 +426,10 @@ 
 
       this->decl_ = decl;
     }
-  if (this->init_ != NULL)
+  if (init_tree != NULL_TREE)
     DECL_INITIAL(this->decl_) =
       Expression::convert_for_assignment(context, this->type(),
-					 this->init_->type(),
-					 this->init_->get_tree(context),
+					 this->init_->type(), init_tree,
 					 this->location());
   if (this->is_address_taken_)
     TREE_ADDRESSABLE(this->decl_) = 1;