Commit 6d729f28 by Jason Merrill Committed by Jason Merrill

re PR c++/43787 (memory copy of empty class (sizeof is one))

	PR c++/43787
gcc:
	* gimplify.c (gimplify_expr): Keep working if gimplify_modify_expr
	returns GS_OK.
	(gimplify_modify_expr_rhs): Return GS_OK if anything changed.
gcc/cp:
	* cp-gimplify.c (cp_gimplify_expr): Remove copies of empty classes.
	* call.c (build_over_call): Don't try to avoid INIT_EXPR copies here.

From-SVN: r159072
parent a2c9b836
2010-05-05 Jason Merrill <jason@redhat.com>
PR c++/43787
* gimplify.c (gimplify_expr): Keep working if gimplify_modify_expr
returns GS_OK.
(gimplify_modify_expr_rhs): Return GS_OK if anything changed.
2010-05-05 Alexandre Oliva <aoliva@redhat.com>
Jakub Jelinek <jakub@redhat.com>
......
2010-05-05 Jason Merrill <jason@redhat.com>
PR c++/43787
* cp-gimplify.c (cp_gimplify_expr): Remove copies of empty classes.
* call.c (build_over_call): Don't try to avoid INIT_EXPR copies here.
2010-05-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/43028
......
......@@ -5778,20 +5778,8 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
{
tree to = stabilize_reference (cp_build_indirect_ref (fa, RO_NULL,
complain));
tree type = TREE_TYPE (to);
if (TREE_CODE (arg) != TARGET_EXPR
&& TREE_CODE (arg) != AGGR_INIT_EXPR
&& is_really_empty_class (type))
{
/* Avoid copying empty classes. */
val = build2 (COMPOUND_EXPR, void_type_node, to, arg);
TREE_NO_WARNING (val) = 1;
val = build2 (COMPOUND_EXPR, type, val, to);
TREE_NO_WARNING (val) = 1;
}
else
val = build2 (INIT_EXPR, DECL_CONTEXT (fn), to, arg);
val = build2 (INIT_EXPR, DECL_CONTEXT (fn), to, arg);
return val;
}
}
......
......@@ -569,6 +569,26 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
&& !useless_type_conversion_p (TREE_TYPE (op1), TREE_TYPE (op0)))
TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR,
TREE_TYPE (op0), op1);
else if ((rhs_predicate_for (op0)) (op1)
&& !(TREE_CODE (op1) == CALL_EXPR
&& CALL_EXPR_RETURN_SLOT_OPT (op1))
&& is_really_empty_class (TREE_TYPE (op0)))
{
/* Remove any copies of empty classes. We check that the RHS
has a simple form so that TARGET_EXPRs and CONSTRUCTORs get
reduced properly, and we leave the return slot optimization
alone because it isn't a copy.
Also drop volatile variables on the RHS to avoid infinite
recursion from gimplify_expr trying to load the value. */
if (!TREE_SIDE_EFFECTS (op1)
|| (DECL_P (op1) && TREE_THIS_VOLATILE (op1)))
*expr_p = op0;
else
*expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
op0, op1);
}
}
ret = GS_OK;
break;
......
2010-05-05 Jason Merrill <jason@redhat.com>
PR c++/43787
* g++.dg/opt/empty1.C: New.
2010-05-05 Janus Weil <janus@gcc.gnu.org>
PR fortran/43696
......
// PR c++/43787
// Test that we don't try to copy *x.
// { dg-do run }
class empty_t {};
int main()
{
empty_t* x = 0;
empty_t y = *x;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment