Commit c652ff83 by Jason Merrill Committed by Jason Merrill

PR c++/20408 - unnecessary code for empty struct.

Here initializing the argument from a TARGET_EXPR isn't an empty class
copy even though the type is !TREE_ADDRESSABLE, so we should check
simple_empty_class_p.

	* call.c (build_call_a): Use simple_empty_class_p.

From-SVN: r271523
parent 52ea1caf
2019-05-22 Jason Merrill <jason@redhat.com> 2019-05-22 Jason Merrill <jason@redhat.com>
PR c++/20408 - unnecessary code for empty struct.
* call.c (build_call_a): Use simple_empty_class_p.
PR c++/86485 - -Wmaybe-unused with empty class ?: PR c++/86485 - -Wmaybe-unused with empty class ?:
* cp-gimplify.c (simple_empty_class_p): Also true for MODIFY_EXPR. * cp-gimplify.c (simple_empty_class_p): Also true for MODIFY_EXPR.
......
...@@ -393,7 +393,7 @@ build_call_a (tree function, int n, tree *argarray) ...@@ -393,7 +393,7 @@ build_call_a (tree function, int n, tree *argarray)
{ {
tree arg = CALL_EXPR_ARG (function, i); tree arg = CALL_EXPR_ARG (function, i);
if (is_empty_class (TREE_TYPE (arg)) if (is_empty_class (TREE_TYPE (arg))
&& ! TREE_ADDRESSABLE (TREE_TYPE (arg))) && simple_empty_class_p (TREE_TYPE (arg), arg, INIT_EXPR))
{ {
tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg)); tree t = build0 (EMPTY_CLASS_EXPR, TREE_TYPE (arg));
arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t); arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
......
...@@ -593,7 +593,7 @@ gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p) ...@@ -593,7 +593,7 @@ gimplify_must_not_throw_expr (tree *expr_p, gimple_seq *pre_p)
non-empty CONSTRUCTORs get reduced properly, and we leave the non-empty CONSTRUCTORs get reduced properly, and we leave the
return slot optimization alone because it isn't a copy. */ return slot optimization alone because it isn't a copy. */
static bool bool
simple_empty_class_p (tree type, tree op, tree_code code) simple_empty_class_p (tree type, tree op, tree_code code)
{ {
if (TREE_CODE (op) == COMPOUND_EXPR) if (TREE_CODE (op) == COMPOUND_EXPR)
......
...@@ -7581,6 +7581,7 @@ extern tree cp_fully_fold_init (tree); ...@@ -7581,6 +7581,7 @@ extern tree cp_fully_fold_init (tree);
extern void clear_fold_cache (void); extern void clear_fold_cache (void);
extern tree lookup_hotness_attribute (tree); extern tree lookup_hotness_attribute (tree);
extern tree process_stmt_hotness_attribute (tree, location_t); extern tree process_stmt_hotness_attribute (tree, location_t);
extern bool simple_empty_class_p (tree, tree, tree_code);
/* in name-lookup.c */ /* in name-lookup.c */
extern tree strip_using_decl (tree); extern tree strip_using_decl (tree);
......
// PR c++/20408
// { dg-additional-options -fdump-tree-gimple }
// { dg-final { scan-tree-dump-times "struct Foo" 2 "gimple" } }
struct Foo {};
void foo(const Foo&);
void bar(Foo);
void fooc(void)
{
foo(Foo());
}
void barc(void)
{
bar(Foo());
}
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