| 1 |
/* Verify that NRV optimizations are prohibited when the LHS is an |
| 2 |
indirect reference to something that may be call-clobbered. */ |
| 3 |
/* { dg-do compile } */ |
| 4 |
/* { dg-options "-O -fdump-tree-optimized" } */ |
| 5 |
|
| 6 |
typedef struct { int x[20]; void *y; } S; |
| 7 |
S nrv_candidate (void); |
| 8 |
void use_result (S); |
| 9 |
void make_escape (S *); |
| 10 |
S global_S; |
| 11 |
void foo (void) |
| 12 |
{ |
| 13 |
S *result; |
| 14 |
S local_S; |
| 15 |
|
| 16 |
/* We can't perform return slot optimization because global_S is |
| 17 |
global and may be clobbered by nrv_candidate. */ |
| 18 |
result = &global_S; |
| 19 |
*result = nrv_candidate (); |
| 20 |
use_result (*result); |
| 21 |
|
| 22 |
/* We can't perform return slot optimization because local_S is |
| 23 |
call_clobbered (its address escapes prior to invoking |
| 24 |
nrv_candidate). */ |
| 25 |
make_escape (&local_S); |
| 26 |
result = &local_S; |
| 27 |
*result = nrv_candidate (); |
| 28 |
use_result (*result); |
| 29 |
} |
| 30 |
|
| 31 |
/* { dg-final { scan-tree-dump-times "return slot optimization" 0 "optimized" } } */ |
| 32 |
|