Patchwork Go patch committed: Don't crash on multiple vars from one result

login
register
mail settings
Submitter Ian Taylor
Date Jan. 4, 2011, 7:46 p.m.
Message ID <mcrbp3wpi3x.fsf@google.com>
Download mbox | patch
Permalink /patch/77523/
State New
Headers show

Comments

Ian Taylor - Jan. 4, 2011, 7:46 p.m.
The Go compiler could crash when initializing multiple variables from a
function call which returns only a single result.  This patch avoids the
crash.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 7415f23c6431 go/expressions.cc
--- a/go/expressions.cc	Tue Jan 04 11:33:54 2011 -0800
+++ b/go/expressions.cc	Tue Jan 04 11:44:56 2011 -0800
@@ -8898,10 +8898,16 @@ 
   // Call_expression::do_must_eval_in_order when there is an error.
   Call_expression* ce = this->call_->call_expression();
   if (ce == NULL)
-    return Type::make_error_type();
+    {
+      this->set_is_error();
+      return Type::make_error_type();
+    }
   Function_type* fntype = ce->get_function_type();
   if (fntype == NULL)
-    return Type::make_error_type();
+    {
+      this->set_is_error();
+      return Type::make_error_type();
+    }
   const Typed_identifier_list* results = fntype->results();
   if (results == NULL)
     {
@@ -8952,7 +8958,11 @@ 
   tree call_tree = this->call_->get_tree(context);
   if (call_tree == error_mark_node)
     return error_mark_node;
-  gcc_assert(TREE_CODE(TREE_TYPE(call_tree)) == RECORD_TYPE);
+  if (TREE_CODE(TREE_TYPE(call_tree)) != RECORD_TYPE)
+    {
+      gcc_assert(saw_errors());
+      return error_mark_node;
+    }
   tree field = TYPE_FIELDS(TREE_TYPE(call_tree));
   for (unsigned int i = 0; i < this->index_; ++i)
     {