> 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? > > 2023-02-23 Jakub Jelinek <ja...@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;
This makes sense to me. I wonder if we don't want to update abstract origin too like we do in tree-inline? Maybe it is unecessary since we don't do debug info for thunks.... Jan