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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I've tried:
--- gcc/cp/cp-gimplify.c.jj     2019-02-18 20:48:37.666649912 +0100
+++ gcc/cp/cp-gimplify.c        2019-03-05 19:03:17.076410253 +0100
@@ -709,6 +709,16 @@ cp_gimplify_expr (tree *expr_p, gimple_s
                           is_gimple_lvalue, fb_lvalue);
            *expr_p = TREE_OPERAND (*expr_p, 0);
          }
+       else if (TREE_CODE (op1) == TARGET_EXPR
+                && is_really_empty_class (TREE_TYPE (op0))
+                && !TREE_THIS_VOLATILE (op1)
+                && !TREE_ADDRESSABLE (TREE_TYPE (op0)))
+         {
+           gimplify_and_add (op1, pre_p);
+           gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
+                          is_gimple_lvalue, fb_lvalue);
+           *expr_p = TREE_OPERAND (*expr_p, 0);
+         }
        /* P0145 says that the RHS is sequenced before the LHS.
           gimplify_modify_expr gimplifies the RHS before the LHS, but that
           isn't quite strong enough in two cases:
(poor attempt to gimplify the TARGET_EXPRs on the rhs in that case always and
also the lhs, but not actually copy any data in between) but that unfortunately
causes ICEs on g++.dg/cpp0x/initlist-new1.C test (apparently CLEANUP_POINT_EXPR
then makes it through into the IL).
If the empty class has a destructor, then we actually share the same temporary
through gimplify_modify_expr_rhs
        case COND_EXPR:
          /* If we're assigning to a non-register type, push the assignment
             down into the branches.  This is mandatory for ADDRESSABLE types,
             since we cannot generate temporaries for such, but it saves a
             copy in other cases as well.  */
          if (!is_gimple_reg_type (TREE_TYPE (*from_p)))
handling, but we don't do that in this case.

Jason, any ideas?

Reply via email to