Commit 7d277e17 by Jason Merrill Committed by Jason Merrill

PR c++/86485 - simple_empty_class_p

Yet another tweak that would have fixed this bug: we should treat INIT_EXPR
and MODIFY_EXPR differently for determining whether this is a simple empty
class copy, since a TARGET_EXPR on the RHS is direct initialization if
INIT_EXPR but copy if MODIFY_EXPR.

	* cp-gimplify.c (simple_empty_class_p): Also true for MODIFY_EXPR.

From-SVN: r271521
parent 9ee0fb4c
2019-05-22 Jason Merrill <jason@redhat.com>
PR c++/86485 - -Wmaybe-unused with empty class ?:
* cp-gimplify.c (simple_empty_class_p): Also true for MODIFY_EXPR.
2019-05-21 Paolo Carlini <paolo.carlini@oracle.com> 2019-05-21 Paolo Carlini <paolo.carlini@oracle.com>
* parser.c (cp_parser_template_declaration_after_parameters): Use * parser.c (cp_parser_template_declaration_after_parameters): Use
......
...@@ -594,19 +594,20 @@ gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p) ...@@ -594,19 +594,20 @@ gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p)
return slot optimization alone because it isn't a copy. */ return slot optimization alone because it isn't a copy. */
static bool static bool
simple_empty_class_p (tree type, tree op) simple_empty_class_p (tree type, tree op, tree_code code)
{ {
if (TREE_CODE (op) == COMPOUND_EXPR)
return simple_empty_class_p (type, TREE_OPERAND (op, 1), code);
return return
((TREE_CODE (op) == COMPOUND_EXPR (TREE_CODE (op) == EMPTY_CLASS_EXPR
&& simple_empty_class_p (type, TREE_OPERAND (op, 1))) || code == MODIFY_EXPR
|| TREE_CODE (op) == EMPTY_CLASS_EXPR
|| is_gimple_lvalue (op) || is_gimple_lvalue (op)
|| INDIRECT_REF_P (op) || INDIRECT_REF_P (op)
|| (TREE_CODE (op) == CONSTRUCTOR || (TREE_CODE (op) == CONSTRUCTOR
&& CONSTRUCTOR_NELTS (op) == 0 && CONSTRUCTOR_NELTS (op) == 0)
&& !TREE_CLOBBER_P (op))
|| (TREE_CODE (op) == CALL_EXPR || (TREE_CODE (op) == CALL_EXPR
&& !CALL_EXPR_RETURN_SLOT_OPT (op))) && !CALL_EXPR_RETURN_SLOT_OPT (op)))
&& !TREE_CLOBBER_P (op)
&& is_really_empty_class (type, /*ignore_vptr*/true); && is_really_empty_class (type, /*ignore_vptr*/true);
} }
...@@ -715,7 +716,7 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) ...@@ -715,7 +716,7 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR, TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR,
TREE_TYPE (op0), op1); TREE_TYPE (op0), op1);
else if (simple_empty_class_p (TREE_TYPE (op0), op1)) else if (simple_empty_class_p (TREE_TYPE (op0), op1, code))
{ {
/* Remove any copies of empty classes. Also drop volatile /* Remove any copies of empty classes. Also drop volatile
variables on the RHS to avoid infinite recursion from variables on the RHS to avoid infinite recursion from
......
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