]> gcc.gnu.org Git - gcc.git/commitdiff
ipa/102762 - fix ICE with invalid __builtin_va_arg_pack () use
authorRichard Biener <rguenther@suse.de>
Fri, 15 Oct 2021 06:41:57 +0000 (08:41 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 8 Nov 2021 12:35:13 +0000 (13:35 +0100)
We have to be careful to not break the argument space calculation.
If there's not enough arguments just do not append any.

2021-10-15  Richard Biener  <rguenther@suse.de>

PR ipa/102762
* tree-inline.c (copy_bb): Avoid underflowing nargs.

* gcc.dg/torture/pr102762.c: New testcase.

(cherry picked from commit 11a4714860d2df6ba496d55379e7dc702d5fc425)

gcc/testsuite/gcc.dg/torture/pr102762.c [new file with mode: 0644]
gcc/tree-inline.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr102762.c b/gcc/testsuite/gcc.dg/torture/pr102762.c
new file mode 100644 (file)
index 0000000..67c6b00
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* We fail to diagnose the invalid __builtin_va_arg_pack use with -flto.  */
+/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
+
+void log_bad_request();
+void foo(a, b)
+     int a, b;
+{
+  log_bad_request(0, __builtin_va_arg_pack());  /* { dg-error "invalid use" } */
+  foo(0);
+}
index a24b10d04b81deeea611bb5a8c8c9c013cd7100d..6e0c16bc355efa9a8c4460267ec6d9b41144f669 100644 (file)
@@ -2097,7 +2097,13 @@ copy_bb (copy_body_data *id, basic_block bb,
              size_t nargs = nargs_caller;
 
              for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p))
-               nargs--;
+               {
+                 /* Avoid crashing on invalid IL that doesn't have a
+                    varargs function or that passes not enough arguments.  */
+                 if (nargs == 0)
+                   break;
+                 nargs--;
+               }
 
              /* Create the new array of arguments.  */
              size_t nargs_callee = gimple_call_num_args (call_stmt);
This page took 0.088472 seconds and 5 git commands to generate.