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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Testcase for the inliner issue:

struct A { int a; short b; };
A test(A& a) { return a; }
A test1(A& a) { return test(a); }

where the issue is that test() doesn't use DECL_RESULT for its return and thus
declare_return_variable setting up DECL_RESULT mapped to the call LHS doesn't
help.

And the reason why we don't use DECL_RESULT is that we have

 <return_expr 0x7ffff6bb0d40
    type <void_type 0x7ffff6a30f18 void VOID
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6a30f18
        pointer_to_this <pointer_type 0x7ffff6a37000>>
    side-effects
    arg:0 <init_expr 0x7ffff6bb7fc8
        type <record_type 0x7ffff6bbdbd0 A cxx-odr-p type_5 DI
            size <integer_cst 0x7ffff6a29240 constant 64>
            unit-size <integer_cst 0x7ffff6a29258 constant 8>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff6bbdbd0 fields <function_decl 0x7ffff6bd5000 __dt > context
<translation_unit_decl 0x7ffff6a18168 t2.ii>
            full-name "struct A"
            X() X(constX&) this=(X&) n_parents=0 use_template=0
interface-unknown
            pointer_to_this <pointer_type 0x7ffff6bbde70> reference_to_this
<reference_type 0x7ffff6bbdd20> chain <type_decl 0x7ffff6a3ebe0 A>>
        side-effects
        arg:0 <result_decl 0x7ffff6bd1000 D.2798 type <record_type
0x7ffff6bbdbd0 A>
            ignored DI t2.ii:2:1 size <integer_cst 0x7ffff6a29240 64> unit-size
<integer_cst 0x7ffff6a29258 8>
            align:32 warn_if_not_align:0 context <function_decl 0x7ffff6bc0500
test>>
        arg:1 <target_expr 0x7ffff6a09700 type <record_type 0x7ffff6bbdbd0 A>
            side-effects tree_3 arg:0 <var_decl 0x7ffff6a19cf0 D.2823>
...

and gimplification changes the RESULT_DECL return because

  /* If aggregate_value_p is true, then we can return the bare RESULT_DECL.
     Recall that aggregate_value_p is FALSE for any aggregate type that is
     returned in registers.  If we're returning values in registers, then
     we don't want to extend the lifetime of the RESULT_DECL, particularly
     across another call.  In addition, for those aggregates for which
     hard_function_value generates a PARALLEL, we'll die during normal
     expansion of structure assignments; there's special code in expand_return
     to handle this case that does not exist in expand_expr.  */

but the code does something else, using a new temporary register
(here !aggregate_value_p).  The following fixes that.

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index b0ed58ed0f9..e4cf5438e39 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -1873,7 +1873,8 @@ gimplify_return_expr (tree stmt, gimple_seq *pre_p)
      to handle this case that does not exist in expand_expr.  */
   if (!result_decl)
     result = NULL_TREE;
-  else if (aggregate_value_p (result_decl, TREE_TYPE (current_function_decl)))
+  else if (aggregate_value_p (result_decl, TREE_TYPE (current_function_decl))
+          || !is_gimple_reg_type (TREE_TYPE (result_decl)))
     {
       if (!poly_int_tree_p (DECL_SIZE (result_decl)))
        {

Reply via email to