2014-04-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / nrv4.c
blobe213d860e2787f68efa4e657f9b964e8d21300c9
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" } */
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)
13 S *result;
14 S local_S;
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);
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);
31 /* { dg-final { scan-tree-dump-times "return slot optimization" 0 "optimized" } } */
32 /* { dg-final { cleanup-tree-dump "optimized" } } */