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