This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Go patch committed: Don't crash building erroneous variable initializer


This patch to the Go frontend avoids crashing when building an erroneous
variable initializer.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r 1e80ea45a4fc go/gogo-tree.cc
--- a/go/gogo-tree.cc	Tue Dec 21 15:59:55 2010 -0800
+++ b/go/gogo-tree.cc	Tue Dec 21 17:10:43 2010 -0800
@@ -757,7 +757,7 @@
 	      pop_cfun();
 	    }
 
-	  if (var_init_tree != NULL_TREE)
+	  if (var_init_tree != NULL_TREE && var_init_tree != error_mark_node)
 	    {
 	      if (no->var_value()->init() == NULL
 		  && !no->var_value()->has_pre_init())
@@ -1209,10 +1209,13 @@
 
   Translate_context context(gogo, function, NULL, NULL_TREE);
   tree block_tree = this->preinit_->get_tree(&context);
+  if (block_tree == error_mark_node)
+    return error_mark_node;
   gcc_assert(TREE_CODE(block_tree) == BIND_EXPR);
   tree statements = BIND_EXPR_BODY(block_tree);
-  while (TREE_CODE(statements) == TRY_FINALLY_EXPR
-	 || TREE_CODE(statements) == TRY_CATCH_EXPR)
+  while (statements != NULL_TREE
+	 && (TREE_CODE(statements) == TRY_FINALLY_EXPR
+	     || TREE_CODE(statements) == TRY_CATCH_EXPR))
     statements = TREE_OPERAND(statements, 0);
 
   // It's possible to have pre-init statements without an initializer
@@ -1220,6 +1223,8 @@
   if (this->init_ != NULL)
     {
       tree rhs_tree = this->init_->get_tree(&context);
+      if (rhs_tree == error_mark_node)
+	return error_mark_node;
       if (var_decl == NULL_TREE)
 	append_to_statement_list(rhs_tree, &statements);
       else
@@ -1228,6 +1233,8 @@
 							this->init_->type(),
 							rhs_tree,
 							this->location());
+	  if (val == error_mark_node)
+	    return error_mark_node;
 	  tree set = fold_build2_loc(this->location(), MODIFY_EXPR,
 				     void_type_node, var_decl, val);
 	  append_to_statement_list(set, &statements);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]