diff mbox series

Go patch committed: Don't crash on a, b := int(0)

Message ID CAOyqgcUcsMwAZY8Z5rfAsqoyxx=fqD4jf1ggGo4O=A6oyt522w@mail.gmail.com
State New
Headers show
Series Go patch committed: Don't crash on a, b := int(0) | expand

Commit Message

Ian Lance Taylor Aug. 11, 2021, 2:36 a.m. UTC
This patch the Go frontend avoids a crash on the invalid code "a, b :=
int(0)".  This fixes GCC PR 101851.  Bootstrapped and ran Go testsuite
on x86_64-pc-linux-gnu.  Committed to mainline.

Ian
498e91bf7d6a8000bb4b74f95c404064b8eac644
diff mbox series

Patch

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index b983fdab35c..be092de568b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@ 
-d5d51242efc432fa62d4e9b141b01c280af32d19
+7e092d2cc5af7648036496485b639f2c9db2f2d8
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index f462b0e2a34..67917dac95d 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -11202,12 +11202,23 @@  Call_expression::do_lower(Gogo* gogo, Named_object* function,
 {
   Location loc = this->location();
 
+  if (this->is_error_expression())
+    return Expression::make_error(loc);
+
   // A type cast can look like a function call.
   if (this->fn_->is_type_expression()
       && this->args_ != NULL
       && this->args_->size() == 1)
-    return Expression::make_cast(this->fn_->type(), this->args_->front(),
-				 loc);
+    {
+      if (this->expected_result_count_ != 0
+	  && this->expected_result_count_ != 1)
+	{
+	  this->report_error(_("type conversion result count mismatch"));
+	  return Expression::make_error(loc);
+	}
+      return Expression::make_cast(this->fn_->type(), this->args_->front(),
+				   loc);
+    }
 
   // Because do_type will return an error type and thus prevent future
   // errors, check for that case now to ensure that the error gets