Patchwork Go patch committed: Don't crash if constant has undefined type

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

Comments

Ian Taylor - March 3, 2011, 12:42 a.m.
This patch to the Go frontend avoids a crash if a constant has a
declared but undefined type.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 8ec65d0d172b go/gogo-tree.cc
--- a/go/gogo-tree.cc	Wed Mar 02 16:12:58 2011 -0800
+++ b/go/gogo-tree.cc	Wed Mar 02 16:37:20 2011 -0800
@@ -926,7 +926,16 @@ 
 	  {
 	    Type* type = named_constant->type();
 	    if (type != NULL && !type->is_abstract())
-	      expr_tree = fold_convert(type->get_tree(gogo), expr_tree);
+	      {
+		if (!type->is_undefined())
+		  expr_tree = fold_convert(type->get_tree(gogo), expr_tree);
+		else
+		  {
+		    // Make sure we report the error.
+		    type->base();
+		    expr_tree = error_mark_node;
+		  }
+	      }
 	    if (expr_tree == error_mark_node)
 	      decl = error_mark_node;
 	    else if (INTEGRAL_TYPE_P(TREE_TYPE(expr_tree)))