From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id E22323858284; Fri, 24 Feb 2023 10:06:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E22323858284 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677233168; bh=TiwUOtcZ5bV+EqMZ4LEHGBwUz7pDtmEJ0fFDuSHxlwk=; h=From:To:Subject:Date:From; b=whl+YD9E48cwSVlGv+ZgHCp1pey5ubyM4v12QibRY0fTG8YWnnsaLwzly1M56GDK4 pDR8S1zaIpF8E+R+3DyypcRLnbd20cE6ivoQEXNxwwGbvrl+cswOt1Xiaip5KRdz5c c3NkdY2RTfd1Y/0o0BH1FDTHyJHBpaAig+qTKIpA= 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 r13-6319] cgraphclones: Don't share DECL_ARGUMENTS between thunk and its artificial thunk [PR108854] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 0ccfa3884f638816af0f5a3f0ee2695e0771ef6d X-Git-Newrev: 2f1691be517fcdcabae9cd671ab511eb0e08b1d5 Message-Id: <20230224100608.E22323858284@sourceware.org> Date: Fri, 24 Feb 2023 10:06:08 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2f1691be517fcdcabae9cd671ab511eb0e08b1d5 commit r13-6319-g2f1691be517fcdcabae9cd671ab511eb0e08b1d5 Author: Jakub Jelinek Date: Fri Feb 24 11:05:27 2023 +0100 cgraphclones: Don't share DECL_ARGUMENTS between thunk and its artificial thunk [PR108854] The following testcase ICEs on x86_64-linux with -m32. The problem is we create an artificial thunk and because of -fPIC, ia32 and thunk destination which doesn't bind locally can't use a mi thunk. The ICE is because during expansion to RTL we see SSA_NAME for a PARM_DECL, but the PARM_DECL doesn't have DECL_CONTEXT of the current function. This is because duplicate_thunk_for_node creates a new DECL_ARGUMENTS chain only if some arguments need modification. The following patch fixes it by copying the DECL_ARGUMENTS list even if the arguments can stay as is, to update DECL_CONTEXT on them. While for mi thunks it doesn't really matter because we don't use those arguments in any way, for other thunks it is important. 2023-02-23 Jakub Jelinek PR middle-end/108854 * cgraphclones.cc (duplicate_thunk_for_node): If no parameter changes are needed, copy at least DECL_ARGUMENTS PARM_DECL nodes and adjust their DECL_CONTEXT. * g++.dg/opt/pr108854.C: New test. Diff: --- gcc/cgraphclones.cc | 12 +++++++++++- gcc/testsuite/g++.dg/opt/pr108854.C | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc index 4a4773ec565..7c5d3b2842c 100644 --- a/gcc/cgraphclones.cc +++ b/gcc/cgraphclones.cc @@ -218,7 +218,17 @@ duplicate_thunk_for_node (cgraph_node *thunk, cgraph_node *node) body_adj.modify_formal_parameters (); } else - new_decl = copy_node (thunk->decl); + { + new_decl = copy_node (thunk->decl); + for (tree *arg = &DECL_ARGUMENTS (new_decl); + *arg; arg = &DECL_CHAIN (*arg)) + { + tree next = DECL_CHAIN (*arg); + *arg = copy_node (*arg); + DECL_CONTEXT (*arg) = new_decl; + DECL_CHAIN (*arg) = next; + } + } gcc_checking_assert (!DECL_STRUCT_FUNCTION (new_decl)); gcc_checking_assert (!DECL_INITIAL (new_decl)); diff --git a/gcc/testsuite/g++.dg/opt/pr108854.C b/gcc/testsuite/g++.dg/opt/pr108854.C new file mode 100644 index 00000000000..9f2d9030f75 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr108854.C @@ -0,0 +1,37 @@ +// PR middle-end/108854 +// { dg-do compile { target c++11 } } +// { dg-options "-O3" } +// { dg-additional-options "-fPIC" { target fpic } } + +struct A { A (int); ~A (); }; +struct B { B (int, bool); ~B (); }; +template +struct C { void m1 (T); void m2 (T &&); }; +class D; +struct E { virtual void m3 (); }; +template +struct F { virtual bool m4 (D &); }; +struct D { virtual D m5 () { return D (); } }; +void foo (void *, void *); +struct G { + int a; + C b; + void m4 (D &r) { B l (a, true); r.m5 (); b.m1 (&r); b.m2 (&r); } +}; +struct H : E, F { + template + H (int, T); + bool m4 (D &r) { A l (a); b.m4 (r); if (c) return true; } // { dg-warning "control reaches end of non-void function" } + int a; + bool c; + G b; +}; +inline void bar (F &p) { D s, t; p.m4 (t); foo (&p, &s); } +enum I { I1, I2 }; +template +struct J; +template +void baz () { int g = 0, h = 0; T i (g, h); bar (i); } +template +void qux () { baz > (); } +void corge () { qux (); qux (); }