summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/nrv4.c
blob: e213d860e2787f68efa4e657f9b964e8d21300c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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[20]; 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" } } */