https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90501

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #7)
> So we are already considering _some_ LHS of return-slot-opt calls as having
> their address taken:
> 
>       if (visit_addr
>           && gimple_call_return_slot_opt_p (call_stmt)
>           && gimple_call_lhs (call_stmt) != NULL_TREE
>           && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call_stmt))))
>         ret |= visit_addr (stmt, gimple_call_lhs (call_stmt),
>                            gimple_call_lhs (call_stmt), data);
> 
> but only those with TREE_ADDRESSABLE type (non-copyable ones).  So not sure
> if the error lies with the D frontend here, I don't remember much around
> the design of the return-slot opt.
> 
> So we can either try to fixup during inlining (we already do for the
> !DECL_BY_REFERENCE case) or we can avoid removing TREE_ADDRESSABLE by
> adjusting the above.
> 
> IIRC at some point build_fold_addr_expr marked the base addressable,
> that might explain the lack of doing this during inlining.
> 
> Index: gcc/tree-inline.c
> ===================================================================
> --- gcc/tree-inline.c   (revision 271282)
> +++ gcc/tree-inline.c   (working copy)
> @@ -3540,6 +3540,7 @@ declare_return_variable (copy_body_data
>              taken by alias analysis.  */
>           gcc_assert (TREE_CODE (return_slot) != SSA_NAME);
>           var = return_slot_addr;
> +         mark_addressable (return_slot);
>         }
>        else
>         {
> 
> fixes the testcase.

Testing went fine for this (obviously).  Waiting for Iains feedback on the
question from Jakub.  Not sure if we should assert somewhere that the
type of a DECL_BY_REFERENCE decl has to be TREE_ADDRESSABLE (and what that
would break).

Reply via email to