Debian Codegraph @

libgomp/testsuite/libgomp.c++/imperfect-destructor.C

raw
1 /* { dg-do run } */
2
3 /* Make sure destructors are called for class variables bound
4 in intervening code. */
5
6 static int f1count[3], f2count[3];
7 static int g1count[3], g2count[3];
8
9 static int ccount[3], dcount[3];
10
11 class C {
12 public:
13 int n;
14 C (int nn) { n = nn; ccount[n]++; }
15 ~C () { dcount[n]++; n = 0; }
16 };
17
18 #ifndef __cplusplus
19 extern void abort (void);
20 #else
21 extern "C" void abort (void);
22 #endif
23
24 int f1 (int depth, int iter)
25 {
26 f1count[depth]++;
27 return iter;
28 }
29
30 int f2 (int depth, int iter)
31 {
32 f2count[depth]++;
33 return iter;
34 }
35
36 int g1 (int depth, int iter)
37 {
38 g1count[depth]++;
39 return iter;
40 }
41
42 int g2 (int depth, int iter)
43 {
44 g2count[depth]++;
45 return iter;
46 }
47
48 void s1 (int a1, int a2, int a3)
49 {
50 int i, j, k;
51
52 #pragma omp for collapse(3)
53 for (i = 0; i < a1; i++)
54 {
55 C local0(0);
56 f1 (local0.n, i);
57 {
58 g1 (local0.n, i);
59 for (j = 0; j < a2; j++)
60 {
61 C local1(1);
62 f1 (local1.n, j);
63 {
64 g1 (local1.n, j);
65 for (k = 0; k < a3; k++)
66 {
67 C local2(2);
68 f1 (local2.n, k);
69 {
70 g1 (local2.n, k);
71 g2 (local2.n, k);
72 }
73 f2 (local2.n, k);
74 }
75 g2 (local1.n, j);
76 }
77 f2 (local1.n, j);
78 }
79 g2 (local0.n, i);
80 }
81 f2 (local0.n, i);
82 }
83 }
84
85 int
86 main (void)
87 {
88 f1count[0] = 0;
89 f1count[1] = 0;
90 f1count[2] = 0;
91 f2count[0] = 0;
92 f2count[1] = 0;
93 f2count[2] = 0;
94
95 g1count[0] = 0;
96 g1count[1] = 0;
97 g1count[2] = 0;
98 g2count[0] = 0;
99 g2count[1] = 0;
100 g2count[2] = 0;
101
102 s1 (3, 4, 5);
103
104 /* All intervening code at the same depth must be executed the same
105 number of times. */
106 if (f1count[0] != f2count[0]) abort ();
107 if (f1count[1] != f2count[1]) abort ();
108 if (f1count[2] != f2count[2]) abort ();
109 if (g1count[0] != f1count[0]) abort ();
110 if (g2count[0] != f1count[0]) abort ();
111 if (g1count[1] != f1count[1]) abort ();
112 if (g2count[1] != f1count[1]) abort ();
113 if (g1count[2] != f1count[2]) abort ();
114 if (g2count[2] != f1count[2]) abort ();
115
116 /* Intervening code must be executed at least as many times as the loop
117 that encloses it. */
118 if (f1count[0] < 3) abort ();
119 if (f1count[1] < 3 * 4) abort ();
120
121 /* Intervening code must not be executed more times than the number
122 of logical iterations. */
123 if (f1count[0] > 3 * 4 * 5) abort ();
124 if (f1count[1] > 3 * 4 * 5) abort ();
125
126 /* Check that the innermost loop body is executed exactly the number
127 of logical iterations expected. */
128 if (f1count[2] != 3 * 4 * 5) abort ();
129
130 /* Check that each class object declared in intervening code was
131 constructed and destructed an equal number of times. */
132 if (ccount[0] != dcount[0]) abort ();
133 if (ccount[1] != dcount[1]) abort ();
134 if (ccount[2] != dcount[2]) abort ();
135 }