aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2019-05-22 17:39:08 -0400
committerJason Merrill <jason@gcc.gnu.org>2019-05-22 17:39:08 -0400
commitc652ff83124334837dc16626f9e1040e4fe41fc9 (patch)
treeda16d1ea2a867756a78e819cf1274de329d6c07b /gcc
parent52ea1caf28cdcdff8c9b2be844e3f1be6c369f16 (diff)
downloadgcc-c652ff83124334837dc16626f9e1040e4fe41fc9.zip
gcc-c652ff83124334837dc16626f9e1040e4fe41fc9.tar.gz
gcc-c652ff83124334837dc16626f9e1040e4fe41fc9.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/cp/cp-gimplify.c2
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/testsuite/g++.dg/tree-ssa/empty-3.C16
5 files changed, 22 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6c98696..88baf86 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
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 ?:
* cp-gimplify.c (simple_empty_class_p): Also true for MODIFY_EXPR.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1e16785..4d9331f 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -393,7 +393,7 @@ build_call_a (tree function, int n, tree *argarray)
{
tree arg = CALL_EXPR_ARG (function, i);
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));
arg = build2 (COMPOUND_EXPR, TREE_TYPE (t), arg, t);
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 30937b1..7b9607d 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -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
return slot optimization alone because it isn't a copy. */
-static bool
+bool
simple_empty_class_p (tree type, tree op, tree_code code)
{
if (TREE_CODE (op) == COMPOUND_EXPR)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 45a6a70..7ad3c6b 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7581,6 +7581,7 @@ extern tree cp_fully_fold_init (tree);
extern void clear_fold_cache (void);
extern tree lookup_hotness_attribute (tree);
extern tree process_stmt_hotness_attribute (tree, location_t);
+extern bool simple_empty_class_p (tree, tree, tree_code);
/* in name-lookup.c */
extern tree strip_using_decl (tree);
diff --git a/gcc/testsuite/g++.dg/tree-ssa/empty-3.C b/gcc/testsuite/g++.dg/tree-ssa/empty-3.C
new file mode 100644
index 0000000..f340bd4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tree-ssa/empty-3.C
@@ -0,0 +1,16 @@
+// 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());
+}