Debian Codegraph @

libgomp/testsuite/libgomp.c++/attrs-imperfect4.C

raw
1 /* { dg-do run } */
2
3 /* Like imperfect2.c, but includes blocks that are themselves intervening
4 code. */
5
6 static int f1count[3], f2count[3];
7 static int g1count[3], g2count[3];
8
9 #ifndef __cplusplus
10 extern void abort (void);
11 #else
12 extern "C" void abort (void);
13 #endif
14
15 int f1 (int depth, int iter)
16 {
17 f1count[depth]++;
18 return iter;
19 }
20
21 int f2 (int depth, int iter)
22 {
23 f2count[depth]++;
24 return iter;
25 }
26
27 int g1 (int depth, int iter)
28 {
29 g1count[depth]++;
30 return iter;
31 }
32
33 int g2 (int depth, int iter)
34 {
35 g2count[depth]++;
36 return iter;
37 }
38
39 void s1 (int a1, int a2, int a3)
40 {
41 int i, j, k;
42
43 [[ omp :: directive (for, collapse(3)) ]]
44 for (i = 0; i < a1; i++)
45 {
46 { f1 (0, i); }
47 {
48 g1 (0, i);
49 for (j = 0; j < a2; j++)
50 {
51 { f1 (1, j); }
52 {
53 { g1 (1, j); }
54 for (k = 0; k < a3; k++)
55 {
56 f1 (2, k);
57 {
58 g1 (2, k);
59 g2 (2, k);
60 }
61 f2 (2, k);
62 }
63 { g2 (1, j); }
64 }
65 { f2 (1, j); }
66 }
67 { g2 (0, i); }
68 }
69 { f2 (0, i); }
70 }
71 }
72
73 int
74 main (void)
75 {
76 f1count[0] = 0;
77 f1count[1] = 0;
78 f1count[2] = 0;
79 f2count[0] = 0;
80 f2count[1] = 0;
81 f2count[2] = 0;
82
83 g1count[0] = 0;
84 g1count[1] = 0;
85 g1count[2] = 0;
86 g2count[0] = 0;
87 g2count[1] = 0;
88 g2count[2] = 0;
89
90 s1 (3, 4, 5);
91
92 /* All intervening code at the same depth must be executed the same
93 number of times. */
94 if (f1count[0] != f2count[0]) abort ();
95 if (f1count[1] != f2count[1]) abort ();
96 if (f1count[2] != f2count[2]) abort ();
97 if (g1count[0] != f1count[0]) abort ();
98 if (g2count[0] != f1count[0]) abort ();
99 if (g1count[1] != f1count[1]) abort ();
100 if (g2count[1] != f1count[1]) abort ();
101 if (g1count[2] != f1count[2]) abort ();
102 if (g2count[2] != f1count[2]) abort ();
103
104 /* Intervening code must be executed at least as many times as the loop
105 that encloses it. */
106 if (f1count[0] < 3) abort ();
107 if (f1count[1] < 3 * 4) abort ();
108
109 /* Intervening code must not be executed more times than the number
110 of logical iterations. */
111 if (f1count[0] > 3 * 4 * 5) abort ();
112 if (f1count[1] > 3 * 4 * 5) abort ();
113
114 /* Check that the innermost loop body is executed exactly the number
115 of logical iterations expected. */
116 if (f1count[2] != 3 * 4 * 5) abort ();
117 }