+2020-03-19 Jason Merrill <jason@redhat.com>
+
+ PR c++/94175
+ * cp-gimplify.c (simple_empty_class_p): Look through
+ SIMPLE_TARGET_EXPR_P.
+ (cp_gimplify_expr) [MODIFY_EXPR]: Likewise.
+ [RETURN_EXPR]: Avoid producing 'return *retval;'.
+ * call.c (build_call_a): Strip TARGET_EXPR from empty class arg.
+ * cp-tree.h (SIMPLE_TARGET_EXPR_P): Check that TARGET_EXPR_INITIAL
+ is non-null.
+
2020-03-19 Jakub Jelinek <jakub@redhat.com>
PR c++/93931
if (is_empty_class (TREE_TYPE (arg))
&& simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
{
+ while (TREE_CODE (arg) == TARGET_EXPR)
+ /* We're disconnecting the initializer from its target,
+ don't create a temporary. */
+ arg = TARGET_EXPR_INITIAL (arg);
tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
CALL_EXPR_ARG (function, i) = arg;
{
if (TREE_CODE (op) == COMPOUND_EXPR)
return simple_empty_class_p (type, TREE_OPERAND (op, 1), code);
+ if (SIMPLE_TARGET_EXPR_P (op)
+ && TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
+ /* The TARGET_EXPR is itself a simple copy, look through it. */
+ return simple_empty_class_p (type, TARGET_EXPR_INITIAL (op), code);
return
(TREE_CODE (op) == EMPTY_CLASS_EXPR
|| code == MODIFY_EXPR
else if (simple_empty_class_p (TREE_TYPE (op0), op1, code))
{
+ while (TREE_CODE (op1) == TARGET_EXPR)
+ /* We're disconnecting the initializer from its target,
+ don't create a temporary. */
+ op1 = TARGET_EXPR_INITIAL (op1);
+
/* Remove any copies of empty classes. Also drop volatile
variables on the RHS to avoid infinite recursion from
gimplify_expr trying to load the value. */
gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
is_gimple_lvalue, fb_lvalue);
*expr_p = TREE_OPERAND (*expr_p, 0);
+ if (code == RETURN_EXPR && REFERENCE_CLASS_P (*expr_p))
+ /* Avoid 'return *<retval>;' */
+ *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
|| TREE_CODE (TREE_OPERAND (*expr_p, 0)) == MODIFY_EXPR))
{
expr_p = &TREE_OPERAND (*expr_p, 0);
- code = TREE_CODE (*expr_p);
/* Avoid going through the INIT_EXPR case, which can
degrade INIT_EXPRs into AGGR_INIT_EXPRs. */
goto modify_expr_case;
the initializer has void type, it's doing something more complicated. */
#define SIMPLE_TARGET_EXPR_P(NODE) \
(TREE_CODE (NODE) == TARGET_EXPR \
+ && TARGET_EXPR_INITIAL (NODE) \
&& !VOID_TYPE_P (TREE_TYPE (TARGET_EXPR_INITIAL (NODE))))
/* True if EXPR expresses direct-initialization of a TYPE. */