From 7229d1d3e78b68f38a594eec415f3ac07c2ef082 Mon Sep 17 00:00:00 2001 From: jconner Date: Fri, 1 Sep 2006 16:56:45 +0000 Subject: [PATCH] 2006-09-01 Josh Conner 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 | 7 +++++++ gcc/testsuite/gcc.dg/nrv3.c | 30 ++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/nrv4.c | 33 +++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/nrv5.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/nrv3.c create mode 100644 gcc/testsuite/gcc.dg/nrv4.c create mode 100644 gcc/testsuite/gcc.dg/nrv5.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cec12fa..df6e40f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2006-09-01 Josh Conner + + 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 PR c++/23287 diff --git a/gcc/testsuite/gcc.dg/nrv3.c b/gcc/testsuite/gcc.dg/nrv3.c new file mode 100644 index 0000000..2b0147d --- /dev/null +++ b/gcc/testsuite/gcc.dg/nrv3.c @@ -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 index 0000000..0560d5d --- /dev/null +++ b/gcc/testsuite/gcc.dg/nrv4.c @@ -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 index 0000000..ecca562 --- /dev/null +++ b/gcc/testsuite/gcc.dg/nrv5.c @@ -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" } } */ -- 2.7.4