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.
This commit is contained in:
Richard Biener 2021-10-15 08:41:57 +02:00
parent be072bfa5b
commit 11a4714860
2 changed files with 18 additions and 1 deletions

View file

@ -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);
}

View file

@ -2117,7 +2117,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))
{
/* 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);