From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 183FD3857C4F; Fri, 1 Oct 2021 06:26:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 183FD3857C4F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-4031] middle-end/102518 - avoid invalid GIMPLE during inlining X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: ea0b5b656a0e90bc9bb3ab0920796b24a9387d76 X-Git-Newrev: 3a7f20ed26416b56df6f3c8240f3c65a5715b17d Message-Id: <20211001062638.183FD3857C4F@sourceware.org> Date: Fri, 1 Oct 2021 06:26:38 +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: Fri, 01 Oct 2021 06:26:38 -0000 https://gcc.gnu.org/g:3a7f20ed26416b56df6f3c8240f3c65a5715b17d commit r12-4031-g3a7f20ed26416b56df6f3c8240f3c65a5715b17d Author: Richard Biener Date: Thu Sep 30 15:05:53 2021 +0200 middle-end/102518 - avoid invalid GIMPLE during inlining When inlining we have to avoid mapping a non-lvalue parameter value into a context that prevents the parameter to be a register. Formerly the register were TREE_ADDRESSABLE but now it can be just DECL_NOT_GIMPLE_REG_P. 2021-09-30 Richard Biener PR middle-end/102518 * tree-inline.c (setup_one_parameter): Avoid substituting an invariant into contexts where a GIMPLE register is not valid. * gcc.dg/torture/pr102518.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr102518.c | 12 ++++++++++++ gcc/tree-inline.c | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr102518.c b/gcc/testsuite/gcc.dg/torture/pr102518.c new file mode 100644 index 00000000000..bd181ec9d99 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr102518.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +struct A { + int *x; +}; +int i; +int f(int *const c) { + struct A * b = (struct A *)(&c); + return b->x != 0; +} +void g() { f(&i); } + diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 5e50e8013e2..e292a144967 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3490,7 +3490,11 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, /* We may produce non-gimple trees by adding NOPs or introduce invalid sharing when the value is not constant or DECL. And we need to make sure that it cannot be modified from another path in the callee. */ - if ((is_gimple_min_invariant (value) + if (((is_gimple_min_invariant (value) + /* When the parameter is used in a context that forces it to + not be a GIMPLE register avoid substituting something that + is not a decl there. */ + && ! DECL_NOT_GIMPLE_REG_P (p)) || (DECL_P (value) && TREE_READONLY (value)) || (auto_var_in_fn_p (value, id->dst_fn) && !TREE_ADDRESSABLE (value)))