Patchwork Go patch committed: Don't crash on invalid closure

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

Comments

Ian Taylor - Dec. 14, 2010, 11:10 p.m.
This patch to the Go frontend avoids a compiler crash on an invalid
closure.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 745d86b87ca2 go/gogo-tree.cc
--- a/go/gogo-tree.cc	Tue Dec 14 14:56:03 2010 -0800
+++ b/go/gogo-tree.cc	Tue Dec 14 15:07:38 2010 -0800
@@ -1313,14 +1313,19 @@ 
 	      push_struct_function(decl);
 
 	      tree closure_decl = this->closure_var_->get_tree(gogo, no);
-
-	      DECL_ARTIFICIAL(closure_decl) = 1;
-	      DECL_IGNORED_P(closure_decl) = 1;
-	      TREE_USED(closure_decl) = 1;
-	      DECL_ARG_TYPE(closure_decl) = TREE_TYPE(closure_decl);
-	      TREE_READONLY(closure_decl) = 1;
-
-	      DECL_STRUCT_FUNCTION(decl)->static_chain_decl = closure_decl;
+	      if (closure_decl == error_mark_node)
+		this->fndecl_ = error_mark_node;
+	      else
+		{
+		  DECL_ARTIFICIAL(closure_decl) = 1;
+		  DECL_IGNORED_P(closure_decl) = 1;
+		  TREE_USED(closure_decl) = 1;
+		  DECL_ARG_TYPE(closure_decl) = TREE_TYPE(closure_decl);
+		  TREE_READONLY(closure_decl) = 1;
+
+		  DECL_STRUCT_FUNCTION(decl)->static_chain_decl = closure_decl;
+		}
+
 	      pop_cfun();
 	    }
 	}