+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
--- /dev/null
+/* 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" } } */
--- /dev/null
+/* 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" } } */
+
--- /dev/null
+/* 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" } } */