| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2 -fno-exceptions" } */ |
| 3 |
struct S |
| 4 |
{ |
| 5 |
inline int fn1 () const { return s; } |
| 6 |
__attribute__ ((noinline, noclone)) S *fn2 (int); |
| 7 |
__attribute__ ((noinline, noclone)) void fn3 (); |
| 8 |
__attribute__ ((noinline, noclone)) static S *fn4 (int); |
| 9 |
S (int i) : s (i) {} |
| 10 |
int s; |
| 11 |
}; |
| 12 |
|
| 13 |
int a = 0; |
| 14 |
S *b = 0; |
| 15 |
|
| 16 |
S * |
| 17 |
S::fn2 (int i) |
| 18 |
{ |
| 19 |
a++; |
| 20 |
if (a == 1) |
| 21 |
return b; |
| 22 |
if (a > 3) |
| 23 |
__builtin_abort (); |
| 24 |
b = this; |
| 25 |
return new S (i + s); |
| 26 |
} |
| 27 |
|
| 28 |
S * |
| 29 |
S::fn4 (int i) |
| 30 |
{ |
| 31 |
b = new S (i); |
| 32 |
return b; |
| 33 |
} |
| 34 |
|
| 35 |
void |
| 36 |
S::fn3 () |
| 37 |
{ |
| 38 |
delete this; |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
foo () |
| 43 |
{ |
| 44 |
S *c = S::fn4 (20); |
| 45 |
for (int i = 0; i < 2;) |
| 46 |
{ |
| 47 |
S *d = c->fn2 (c->fn1 () + 10); |
| 48 |
if (c != d) |
| 49 |
{ |
| 50 |
c->fn3 (); |
| 51 |
c = d; |
| 52 |
++i; |
| 53 |
} |
| 54 |
} |
| 55 |
c->fn3 (); |
| 56 |
} |
| 57 |
|
| 58 |
int |
| 59 |
main () |
| 60 |
{ |
| 61 |
foo (); |
| 62 |
} |