re PR c++/23372 (Temporary aggregate copy not elided when passing parameters by value)
authorJason Merrill <jason@redhat.com>
Fri, 18 Mar 2011 15:06:51 +0000 (11:06 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 18 Mar 2011 15:06:51 +0000 (11:06 -0400)
PR c++/23372
* gimplify.c (gimplify_arg): Strip redundant TARGET_EXPR.

From-SVN: r171146

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr23372.C [new file with mode: 0644]

index 11fcfe7f171a9ae8df4dec0b34e15afe0ac0b2c6..712eefe8f0576a65a83e722345752aedd18222d2 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-18  Jason Merrill  <jason@redhat.com>
+
+       PR c++/23372
+       * gimplify.c (gimplify_arg): Strip redundant TARGET_EXPR.
+
 2011-03-18  Richard Guenther  <rguenther@suse.de>
 
        * doc/install.texi (--enable-gold): Remove.
index 400493fa4fe68d5348ef18d1c430061e27c2d74a..0b314a068c393a20d1ebf5e7f6658b2f49453e43 100644 (file)
@@ -2255,7 +2255,17 @@ gimplify_arg (tree *arg_p, gimple_seq *pre_p, location_t call_location)
   if (is_gimple_reg_type (TREE_TYPE (*arg_p)))
     test = is_gimple_val, fb = fb_rvalue;
   else
-    test = is_gimple_lvalue, fb = fb_either;
+    {
+      test = is_gimple_lvalue, fb = fb_either;
+      /* Also strip a TARGET_EXPR that would force an extra copy.  */
+      if (TREE_CODE (*arg_p) == TARGET_EXPR)
+       {
+         tree init = TARGET_EXPR_INITIAL (*arg_p);
+         if (init
+             && !VOID_TYPE_P (TREE_TYPE (init)))
+           *arg_p = init;
+       }
+    }
 
   /* If this is a variable sized type, we must remember the size.  */
   maybe_with_size_expr (arg_p);
index dcd19eadd2625913968d22a7b20f0794624b7bfe..b9c7dd844000bebfc65712194daebee4dd5540e8 100644 (file)
@@ -1,5 +1,7 @@
 2011-03-18  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/opt/pr23372.C: New.
+
        * g++.dg/ext/attrib32.C: Expect errors on the two-names case.
 
 2011-03-18  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
diff --git a/gcc/testsuite/g++.dg/opt/pr23372.C b/gcc/testsuite/g++.dg/opt/pr23372.C
new file mode 100644 (file)
index 0000000..9be4c9c
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/23372
+// { dg-options -fdump-tree-gimple }
+
+// There shouldn't be an assignment to a temporary in the GIMPLE,
+// as that represents a redundant copy.
+// { dg-final { scan-tree-dump-not "=" gimple } }
+
+struct A {
+  int a[1000];
+  //A(A const &);
+};
+void f(A);
+void g(A *a) { f(*a); }
+
+// { dg-final { cleanup-tree-dump gimple } }