public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9226] ipa/102762 - fix ICE with invalid __builtin_va_arg_pack () use
@ 2021-11-08 12:35 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-08 12:35 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:30c18bbfed2fae5ff89841172553951a74125f8e
commit r11-9226-g30c18bbfed2fae5ff89841172553951a74125f8e
Author: Richard Biener <rguenther@suse.de>
Date: Fri Oct 15 08:41:57 2021 +0200
ipa/102762 - fix ICE with invalid __builtin_va_arg_pack () use
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)
Diff:
---
gcc/testsuite/gcc.dg/torture/pr102762.c | 11 +++++++++++
gcc/tree-inline.c | 8 +++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/gcc.dg/torture/pr102762.c b/gcc/testsuite/gcc.dg/torture/pr102762.c
new file mode 100644
index 00000000000..67c6b00ccea
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr102762.c
@@ -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);
+}
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index a24b10d04b8..6e0c16bc355 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-08 12:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08 12:35 [gcc r11-9226] ipa/102762 - fix ICE with invalid __builtin_va_arg_pack () use Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).