diff options
author | Josh Conner <jconner@apple.com> | 2006-09-01 16:56:45 +0000 |
---|---|---|
committer | Josh Conner <jconner@gcc.gnu.org> | 2006-09-01 16:56:45 +0000 |
commit | 39ac09770991ae0a9052fd0865159b0b17d22a3d (patch) | |
tree | f3f5fd6c8e340bea117f39288fa238a3d4bc8c20 /gcc/testsuite/gcc.dg | |
parent | f0ce78583abfc8db21dfa0c577c606c565ef0708 (diff) | |
download | gcc-39ac09770991ae0a9052fd0865159b0b17d22a3d.zip gcc-39ac09770991ae0a9052fd0865159b0b17d22a3d.tar.gz gcc-39ac09770991ae0a9052fd0865159b0b17d22a3d.tar.bz2 |
re PR middle-end/25505 (gcc uses way too much stack space for this code)
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.
From-SVN: r116634
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r-- | gcc/testsuite/gcc.dg/nrv3.c | 30 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/nrv4.c | 33 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/nrv5.c | 28 |
3 files changed, 91 insertions, 0 deletions
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" } } */ |