2006-09-01 Josh Conner <jconner@apple.com>
authorjconner <jconner@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Sep 2006 16:56:45 +0000 (16:56 +0000)
committerjconner <jconner@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 1 Sep 2006 16:56:45 +0000 (16:56 +0000)
PR c++/25505
gcc.dg/nrv3.c: New test.
gcc.dg/nrv4.c: New test.
gcc.dg/nrv5.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@116634 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/nrv3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/nrv4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/nrv5.c [new file with mode: 0644]

index cec12fa..df6e40f 100644 (file)
@@ -1,3 +1,10 @@
+2006-09-01  Josh Conner  <jconner@apple.com>
+
+       PR c++/25505
+       gcc.dg/nrv3.c: New test.
+       gcc.dg/nrv4.c: New test.
+       gcc.dg/nrv5.c: New test.
+
 2006-09-01  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/23287
diff --git a/gcc/testsuite/gcc.dg/nrv3.c b/gcc/testsuite/gcc.dg/nrv3.c
new file mode 100644 (file)
index 0000000..2b0147d
--- /dev/null
@@ -0,0 +1,30 @@
+/* Verify that gimple-level NRV is occurring when values other than the
+   return slot are call-clobbered.  */
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+typedef struct { int x; void *y; } S;
+typedef struct { int a; S b; } T;
+S nrv_candidate (void);
+void use_result (S, int);
+int *ptr;
+void foo (void)
+{
+  S result;
+  T result_arr[10][5];
+
+  int i;
+
+  ptr = &i;
+
+  /* i is call-clobbered for these calls, but result and result_arr
+     aren't.  */
+  result = nrv_candidate ();
+  result_arr[3][4].b = nrv_candidate ();
+
+  use_result (result, i);
+  use_result (result_arr[3][4].b, i);
+}
+
+/* { dg-final { scan-tree-dump-times "return slot optimization" 2 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/nrv4.c b/gcc/testsuite/gcc.dg/nrv4.c
new file mode 100644 (file)
index 0000000..0560d5d
--- /dev/null
@@ -0,0 +1,33 @@
+/* Verify that NRV optimizations are prohibited when the LHS is an
+   indirect reference to something that may be call-clobbered. */
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+typedef struct { int x; void *y; } S;
+S nrv_candidate (void);
+void use_result (S);
+void make_escape (S *);
+S global_S;
+void foo (void)
+{
+  S *result;
+  S local_S;
+
+  /* We can't perform return slot optimization because global_S is
+     global and may be clobbered by nrv_candidate.  */
+  result = &global_S;
+  *result = nrv_candidate ();
+  use_result (*result);
+
+  /* We can't perform return slot optimization because local_S is
+     call_clobbered (its address escapes prior to invoking
+     nrv_candidate).  */
+  make_escape (&local_S);
+  result = &local_S;
+  *result = nrv_candidate ();
+  use_result (*result);
+}
+
+/* { dg-final { scan-tree-dump-times "return slot optimization" 0 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
diff --git a/gcc/testsuite/gcc.dg/nrv5.c b/gcc/testsuite/gcc.dg/nrv5.c
new file mode 100644 (file)
index 0000000..ecca562
--- /dev/null
@@ -0,0 +1,28 @@
+/* Verify that NRV optimizations are prohibited when the LHS is
+   something that may be call-clobbered. */
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+typedef struct { int x; void *y; } S;
+typedef struct { int a; S b; } T;
+S nrv_candidate (void);
+void use_result (S);
+void make_escape (S *);
+void foo (void)
+{
+  S result;
+  T result_arr[10][5];
+
+  make_escape (&result);
+  make_escape (&(result_arr[3][4].b));
+
+  /* Neither call should be allowed to use NRV optimization.  */
+  result = nrv_candidate ();
+  result_arr[3][4].b = nrv_candidate ();
+
+  use_result (result);
+  use_result (result_arr[3][4].b);
+}
+
+/* { dg-final { scan-tree-dump-times "return slot optimization" 0 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */