gcc/
[official-gcc.git] / libgomp / testsuite / libgomp.c / pr33880.c
blob5d719cd635dfee18155092d2623415d8c128fea8
1 /* PR middle-end/33880 */
2 /* { dg-do run } */
4 extern void abort (void);
6 void
7 test1 (void)
9 int i = 0, j = 0;
10 void bar (void)
12 i++;
13 j++;
15 bar ();
16 #pragma omp parallel for num_threads(4)
17 for (i = 0; i < 100; i++)
18 #pragma omp atomic
19 j += 1;
20 if (j != 101)
21 abort ();
22 #pragma omp parallel for lastprivate(i) num_threads(2)
23 for (i = 0; i < 100; i++)
24 #pragma omp atomic
25 j += 1;
26 if (i != 100)
27 abort ();
28 i = 3;
29 bar ();
30 if (j != 202)
31 abort ();
32 if (i != 4)
33 abort ();
36 void
37 test2 (void)
39 int i = -1, j = 99, k, l = 9, m = 0;
40 void bar (void)
42 i++;
43 j++;
44 l++;
45 m++;
47 bar ();
48 #pragma omp parallel for num_threads(4)
49 for (k = i; k < j; k += l)
50 #pragma omp atomic
51 m += 1;
52 bar ();
53 if (i != 1 || j != 101 || l != 11 || m != 12)
54 abort ();
57 void
58 test3 (void)
60 int i, j, k, l, m;
61 void bar (void)
63 #pragma omp parallel for num_threads(4)
64 for (i = j; i < k; i += l)
65 #pragma omp atomic
66 m += 1;
68 void baz (void)
70 #pragma omp parallel for num_threads(2) lastprivate(i)
71 for (i = j; i < k * 2; i += l / 2)
72 #pragma omp atomic
73 m += 1;
75 i = 7;
76 j = 0;
77 k = 100;
78 l = 2;
79 m = 0;
80 bar ();
81 if (j != 0 || k != 100 || l != 2 || m != 50)
82 abort ();
83 baz ();
84 if (i != 200 || j != 0 || k != 100 || l != 2 || m != 250)
85 abort ();
88 void
89 test4 (void)
91 int i, j, k, l, m = 0;
92 int foo (void)
94 return j;
96 int bar (void)
98 return k;
100 int baz (void)
102 return l;
104 j = 0;
105 k = 1000;
106 l = 2;
107 #pragma omp parallel for num_threads(8) lastprivate(i)
108 for (i = foo (); i < bar (); i += baz ())
109 #pragma omp atomic
110 m += 1;
111 if (i != 1000 || m != 500 || j != 0 || k != 1000 || l != 2)
112 abort ();
116 main (void)
118 test1 ();
119 test2 ();
120 test3 ();
121 test4 ();
122 return 0;