From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Jan Hubicka <jh@suse.cz>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] cgraphclones: Don't share DECL_ARGUMENTS between thunk and its artificial thunk [PR108854]
Date: Fri, 24 Feb 2023 09:37:51 +0000 (UTC) [thread overview]
Message-ID: <nycvar.YFH.7.77.849.2302240937450.27913@jbgna.fhfr.qr> (raw)
In-Reply-To: <Y/iFEoRtKXyRe46M@tucnak>
On Fri, 24 Feb 2023, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2023-02-23 Jakub Jelinek <jakub@redhat.com>
>
> 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.
>
> --- gcc/cgraphclones.cc.jj 2023-02-22 20:50:27.417519830 +0100
> +++ gcc/cgraphclones.cc 2023-02-23 17:12:59.875133883 +0100
> @@ -218,7 +218,17 @@ duplicate_thunk_for_node (cgraph_node *t
> 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));
> --- gcc/testsuite/g++.dg/opt/pr108854.C.jj 2023-02-23 17:11:19.275583506 +0100
> +++ gcc/testsuite/g++.dg/opt/pr108854.C 2023-02-23 17:11:02.723822009 +0100
> @@ -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 <typename T>
> +struct C { void m1 (T); void m2 (T &&); };
> +class D;
> +struct E { virtual void m3 (); };
> +template <typename>
> +struct F { virtual bool m4 (D &); };
> +struct D { virtual D m5 () { return D (); } };
> +void foo (void *, void *);
> +struct G {
> + int a;
> + C <D *> b;
> + void m4 (D &r) { B l (a, true); r.m5 (); b.m1 (&r); b.m2 (&r); }
> +};
> +struct H : E, F <int> {
> + template <typename T>
> + 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 <int> &p) { D s, t; p.m4 (t); foo (&p, &s); }
> +enum I { I1, I2 };
> +template <I>
> +struct J;
> +template <class, class T, class, class, class, class>
> +void baz () { int g = 0, h = 0; T i (g, h); bar (i); }
> +template <class, int, I T>
> +void qux () { baz <int, H, int, int, E, J<T>> (); }
> +void corge () { qux <int, I2, I1> (); qux <int, I2, I2> (); }
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)
next prev parent reply other threads:[~2023-02-24 9:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-24 9:36 Jakub Jelinek
2023-02-24 9:37 ` Richard Biener [this message]
2023-02-24 13:30 ` Jan Hubicka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=nycvar.YFH.7.77.849.2302240937450.27913@jbgna.fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=jh@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).