Message ID | 7237749.isj1USbTg8@polaris |
---|---|
State | New |
Headers | show |
Series | Fix segfault during inlining of thunk | expand |
On Wed, Jan 23, 2019 at 10:48 AM Eric Botcazou <ebotcazou@adacore.com> wrote: > > Hi, > > this is a regression present in Ada on the mainline since we switched to using > the internal support for thunks: expand_thunk segfaults during inlining when > trying to access the DECL_RESULT of the special alias built to make the call > from the thunk local, if the DECL_RESULT of the thunk is DECL_BY_REFERENCE. > > It turns out that neither the C++ nor the Ada front-end builds the DECL_RESULT > of this special alias (the C++ front-end apparently doesn't even build that of > the thunk itself so expand_thunk has code to patch this up). Moreover it's a > bit strange to first try: > > restmp = gimple_fold_indirect_ref (resdecl); > > i.e. build the dereference using the type of resdecl and then use the type of > the DECL_RESULT of the alias if this failed. So the attached fix changes this > to using the type of resdecl in the latter case too. > > Bootstrapped/regtested on x86_64-suse-linux, OK for the mainline? OK. I guess the original (cut&paste?) error was to look at DECL_RESULT (alias) instead of DECL_RESULT (thunk_fndecl) which would have made this consistent as well. Richard. > > 2019-01-22 Eric Botcazou <ebotcazou@adacore.com> > > * cgraphunit.c (cgraph_node::expand_thunk): When expanding a GIMPLE > thunk that returns by reference, use the type of the return object > of the thunk instead of that of the alias to build the dereference. > > > 2019-01-23 Eric Botcazou <ebotcazou@adacore.com> > > * gnat.dg/specs/opt4.ads: New test. > > -- > Eric Botcazou
Index: cgraphunit.c =================================================================== --- cgraphunit.c (revision 268071) +++ cgraphunit.c (working copy) @@ -1916,10 +1916,9 @@ cgraph_node::expand_thunk (bool output_a restmp = gimple_fold_indirect_ref (resdecl); if (!restmp) restmp = build2 (MEM_REF, - TREE_TYPE (TREE_TYPE (DECL_RESULT (alias))), + TREE_TYPE (TREE_TYPE (resdecl)), resdecl, - build_int_cst (TREE_TYPE - (DECL_RESULT (alias)), 0)); + build_int_cst (TREE_TYPE (resdecl), 0)); } else if (!is_gimple_reg_type (restype)) {