]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: better arg type checking for selected builtins
authorThan McIntosh <thanm@google.com>
Thu, 6 Oct 2022 19:58:59 +0000 (15:58 -0400)
committerIan Lance Taylor <iant@golang.org>
Fri, 7 Oct 2022 02:15:18 +0000 (19:15 -0700)
Tighten up the argument type checking for Builtin_call_expression to
catch erroneous cases such as

   panic(panic("bad")))

where an argument void type is being passed to panic/alignof/sizeof.

Fixes golang/go#56071.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/439815

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc

index 4793c821eba855647f7840ab084044961ac88e65..10ed3fee67c5659765c1a1757fb4426d41e7a061 100644 (file)
@@ -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.
index 2492d9fe73526a76dbbff5001b055b45a319dc32..247ae1bba34a9182824fb7977fb3bdd5bc03d0ae 100644 (file)
@@ -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: