Go patch committed: better argument checking for builtins

Message ID CAOyqgcXeSRifWKVEE3vW87v7CMJ--04uB=0i=dxKBA=8piwKcA@mail.gmail.com
State New, archived
Headers
Series Go patch committed: better argument checking for builtins |

Commit Message

Ian Lance Taylor Oct. 7, 2022, 2:15 a.m. UTC
  This patch to the Go frontend by Than McIntosh does some better
argument type checking for some builtin functions.  This avoids a
compiler crash on cases like panic(panic("bad")).  This fixes
https://go.dev/issue/56071.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
05c581aef882b3a6369acde2d37a437ef144705c
  

Patch

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 4793c821eba..10ed3fee67c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@ 
-8f1a91aeff400d572857895b7f5e863ec5a4d93e
+50707b4b51266166ce9bcf9de187e35760ec50f9
 
 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 2492d9fe735..247ae1bba34 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10316,7 +10316,12 @@  Builtin_call_expression::do_check_types(Gogo*)
     case BUILTIN_PANIC:
     case BUILTIN_SIZEOF:
     case BUILTIN_ALIGNOF:
-      this->check_one_arg();
+      if (this->check_one_arg())
+        {
+	  Expression* arg = this->one_arg();
+	  if (arg->type()->is_void_type())
+	    this->report_error(_("argument to builtin has void type"));
+        }
       break;
 
     case BUILTIN_RECOVER: