public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Don't crash building erroneous variable initializer
@ 2010-12-22  3:50 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2010-12-22  3:50 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 189 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: crash --]
[-- Type: text/x-diff, Size: 1648 bytes --]

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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-22  1:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-22  3:50 Go patch committed: Don't crash building erroneous variable initializer Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).