From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 61366383B830; Mon, 7 Jun 2021 07:26:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61366383B830 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1255] tree-inline: Fix up __builtin_va_arg_pack handling [PR100898] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: be5efe9c12cb852c788f74f8555e6ab8d755479b X-Git-Newrev: d66a703c8ba86f3ca04cc10c3071696e6d014de6 Message-Id: <20210607072619.61366383B830@sourceware.org> Date: Mon, 7 Jun 2021 07:26:19 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jun 2021 07:26:19 -0000 https://gcc.gnu.org/g:d66a703c8ba86f3ca04cc10c3071696e6d014de6 commit r12-1255-gd66a703c8ba86f3ca04cc10c3071696e6d014de6 Author: Jakub Jelinek Date: Mon Jun 7 09:25:37 2021 +0200 tree-inline: Fix up __builtin_va_arg_pack handling [PR100898] The following testcase ICEs, because gimple_call_arg_ptr (..., 0) asserts that there is at least one argument, while we were using it even if we didn't copy anything just to get a pointer from/to which the zero arguments should be copied. Fixed by guarding the memcpy calls. Also, the code was calling gimple_call_num_args too many times - 5 times instead of 2, so the patch adds two temporaries for those. 2021-06-07 Jakub Jelinek PR middle-end/100898 * tree-inline.c (copy_bb): Only use gimple_call_arg_ptr if memcpy should copy any arguments. Don't call gimple_call_num_args on id->call_stmt or call_stmt more than once. * g++.dg/ext/va-arg-pack-3.C: New test. Diff: --- gcc/testsuite/g++.dg/ext/va-arg-pack-3.C | 18 ++++++++++++++++++ gcc/tree-inline.c | 22 ++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/g++.dg/ext/va-arg-pack-3.C b/gcc/testsuite/g++.dg/ext/va-arg-pack-3.C new file mode 100644 index 00000000000..0e8203ca173 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/va-arg-pack-3.C @@ -0,0 +1,18 @@ +// PR middle-end/100898 + +int a; +int bar (int, ...); + +static inline __attribute__((always_inline)) int +foo (...) +{ + while (a) + return bar (0, __builtin_va_arg_pack ()); + return 0; +} + +void +baz (void) +{ + foo (); +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 05d1a253d5b..4250fd86487 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -2090,27 +2090,29 @@ copy_bb (copy_body_data *id, basic_block bb, tree p; gcall *new_call; vec argarray; - size_t nargs = gimple_call_num_args (id->call_stmt); - size_t n; + size_t nargs_caller = gimple_call_num_args (id->call_stmt); + size_t nargs = nargs_caller; for (p = DECL_ARGUMENTS (id->src_fn); p; p = DECL_CHAIN (p)) nargs--; /* Create the new array of arguments. */ - n = nargs + gimple_call_num_args (call_stmt); + size_t nargs_callee = gimple_call_num_args (call_stmt); + size_t n = nargs + nargs_callee; argarray.create (n); argarray.safe_grow_cleared (n, true); /* Copy all the arguments before '...' */ - memcpy (argarray.address (), - gimple_call_arg_ptr (call_stmt, 0), - gimple_call_num_args (call_stmt) * sizeof (tree)); + if (nargs_callee) + memcpy (argarray.address (), + gimple_call_arg_ptr (call_stmt, 0), + nargs_callee * sizeof (tree)); /* Append the arguments passed in '...' */ - memcpy (argarray.address () + gimple_call_num_args (call_stmt), - gimple_call_arg_ptr (id->call_stmt, 0) - + (gimple_call_num_args (id->call_stmt) - nargs), - nargs * sizeof (tree)); + if (nargs) + memcpy (argarray.address () + nargs_callee, + gimple_call_arg_ptr (id->call_stmt, 0) + + (nargs_caller - nargs), nargs * sizeof (tree)); new_call = gimple_build_call_vec (gimple_call_fn (call_stmt), argarray);