Patchwork Go patch committed: Don't crash when calling new on erroneous type

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

Comments

Ian Taylor - Dec. 21, 2010, 11:19 p.m.
This patch to the Go frontend avoids a crash when calling new with an
erroneous type.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 36326cbb6279 go/expressions.cc
--- a/go/expressions.cc	Tue Dec 21 15:11:44 2010 -0800
+++ b/go/expressions.cc	Tue Dec 21 15:15:40 2010 -0800
@@ -10242,9 +10242,13 @@ 
 Allocation_expression::do_get_tree(Translate_context* context)
 {
   tree type_tree = this->type_->get_tree(context->gogo());
+  if (type_tree == error_mark_node)
+    return error_mark_node;
   tree size_tree = TYPE_SIZE_UNIT(type_tree);
   tree space = context->gogo()->allocate_memory(this->type_, size_tree,
 						this->location());
+  if (space == error_mark_node)
+    return error_mark_node;
   return fold_convert(build_pointer_type(type_tree), space);
 }