]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/OpenMP/for_firstprivate_messages.cpp
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / test / OpenMP / for_firstprivate_messages.cpp
1 // RUN: %clang_cc1 -verify -fopenmp %s
2 // RUN: %clang_cc1 -verify -fopenmp-simd %s
3
4 void foo() {
5 }
6
7 bool foobool(int argc) {
8   return argc;
9 }
10
11 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
12 extern S1 a;
13 class S2 {
14   mutable int a;
15
16 public:
17   S2() : a(0) {}
18   S2(const S2 &s2) : a(s2.a) {}
19   static float S2s;
20   static const float S2sc;
21 };
22 const float S2::S2sc = 0;
23 const S2 b;
24 const S2 ba[5];
25 class S3 {
26   int a;
27   S3 &operator=(const S3 &s3);
28
29 public:
30   S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
31   S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}}
32 };
33 const S3 c;
34 const S3 ca[5];
35 extern const int f;
36 class S4 {
37   int a;
38   S4();
39   S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
40
41 public:
42   S4(int v) : a(v) {}
43 };
44 class S5 {
45   int a;
46   S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
47
48 public:
49   S5() : a(0) {}
50   S5(int v) : a(v) {}
51 };
52 class S6 {
53   int a;
54   S6() : a(0) {}
55
56 public:
57   S6(const S6 &s6) : a(s6.a) {}
58   S6(int v) : a(v) {}
59 };
60
61 S3 h;
62 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
63
64 template <class I, class C>
65 int foomain(int argc, char **argv) {
66   I e(4);
67   C g(5);
68   int i;
69   int &j = i;
70 #pragma omp parallel
71 #pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
72   for (int k = 0; k < argc; ++k)
73     ++k;
74 #pragma omp parallel
75 #pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
76   for (int k = 0; k < argc; ++k)
77     ++k;
78 #pragma omp parallel
79 #pragma omp for firstprivate() // expected-error {{expected expression}}
80   for (int k = 0; k < argc; ++k)
81     ++k;
82 #pragma omp parallel
83 #pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
84   for (int k = 0; k < argc; ++k)
85     ++k;
86 #pragma omp parallel
87 #pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
88   for (int k = 0; k < argc; ++k)
89     ++k;
90 #pragma omp parallel
91 #pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
92   for (int k = 0; k < argc; ++k)
93     ++k;
94 #pragma omp parallel
95 #pragma omp for firstprivate(argc)
96   for (int k = 0; k < argc; ++k)
97     ++k;
98 #pragma omp parallel
99 #pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
100   for (int k = 0; k < argc; ++k)
101     ++k;
102 #pragma omp parallel
103 #pragma omp for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
104   for (int k = 0; k < argc; ++k)
105     ++k;
106 #pragma omp parallel
107 #pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}}
108   for (int k = 0; k < argc; ++k)
109     ++k;
110 #pragma omp parallel
111 #pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
112   for (int k = 0; k < argc; ++k)
113     ++k;
114 #pragma omp parallel
115 #pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
116   for (int k = 0; k < argc; ++k)
117     ++k;
118 #pragma omp parallel
119   {
120     int v = 0;
121     int i;                      // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}}
122 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
123     for (int k = 0; k < argc; ++k) {
124       i = k;
125       v += i;
126     }
127   }
128 #pragma omp parallel shared(i)
129 #pragma omp parallel private(i)
130 #pragma omp for firstprivate(j)
131   for (int k = 0; k < argc; ++k)
132     ++k;
133 #pragma omp parallel
134 #pragma omp for firstprivate(i)
135   for (int k = 0; k < argc; ++k)
136     ++k;
137 #pragma omp parallel
138 #pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
139   for (i = 0; i < argc; ++i)
140     foo();
141 #pragma omp parallel private(i) // expected-note {{defined as private}}
142 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
143   for (i = 0; i < argc; ++i)
144     foo();
145 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
146 #pragma omp for firstprivate(i)       // expected-error {{firstprivate variable must be shared}}
147   for (int k = 0; k < argc; ++k)
148     foo();
149   return 0;
150 }
151
152 void bar(S4 a[2]) {
153 #pragma omp parallel
154 #pragma omp for firstprivate(a)
155   for (int i = 0; i < 2; ++i)
156     foo();
157 }
158
159 namespace A {
160 double x;
161 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
162 }
163 namespace B {
164 using A::x;
165 }
166
167 int main(int argc, char **argv) {
168   const int d = 5;
169   const int da[5] = {0};
170   S4 e(4);
171   S5 g(5);
172   S3 m;
173   S6 n(2);
174   int i;
175   int &j = i;
176 #pragma omp parallel
177 #pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
178   for (i = 0; i < argc; ++i)
179     foo();
180 #pragma omp parallel
181 #pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
182   for (i = 0; i < argc; ++i)
183     foo();
184 #pragma omp parallel
185 #pragma omp for firstprivate() // expected-error {{expected expression}}
186   for (i = 0; i < argc; ++i)
187     foo();
188 #pragma omp parallel
189 #pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
190   for (i = 0; i < argc; ++i)
191     foo();
192 #pragma omp parallel
193 #pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
194   for (i = 0; i < argc; ++i)
195     foo();
196 #pragma omp parallel
197 #pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
198   for (i = 0; i < argc; ++i)
199     foo();
200 #pragma omp parallel
201 #pragma omp for firstprivate(argc)
202   for (i = 0; i < argc; ++i)
203     foo();
204 #pragma omp parallel
205 #pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
206   for (i = 0; i < argc; ++i)
207     foo();
208 #pragma omp parallel
209 #pragma omp for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{no matching constructor for initialization of 'S3'}}
210   for (i = 0; i < argc; ++i)
211     foo();
212 #pragma omp parallel
213 #pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}}
214   for (i = 0; i < argc; ++i)
215     foo();
216 #pragma omp parallel
217 #pragma omp for firstprivate(2 * 2) // expected-error {{expected variable name}}
218   for (i = 0; i < argc; ++i)
219     foo();
220 #pragma omp parallel
221 #pragma omp for firstprivate(ba) // OK
222   for (i = 0; i < argc; ++i)
223     foo();
224 #pragma omp parallel
225 #pragma omp for firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}}
226   for (i = 0; i < argc; ++i)
227     foo();
228 #pragma omp parallel
229 #pragma omp for firstprivate(da) // OK
230   for (i = 0; i < argc; ++i)
231     foo();
232   int xa;
233 #pragma omp parallel
234 #pragma omp for firstprivate(xa) // OK
235   for (i = 0; i < argc; ++i)
236     foo();
237 #pragma omp parallel
238 #pragma omp for firstprivate(S2::S2s) // OK
239   for (i = 0; i < argc; ++i)
240     foo();
241 #pragma omp parallel
242 #pragma omp for firstprivate(S2::S2sc) // OK
243   for (i = 0; i < argc; ++i)
244     foo();
245 #pragma omp parallel
246 #pragma omp for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp for'}}
247   for (i = 0; i < argc; ++i)
248     foo();
249 #pragma omp parallel
250 #pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
251   for (i = 0; i < argc; ++i)
252     foo();
253 #pragma omp parallel
254 #pragma omp for firstprivate(m) // OK
255   for (i = 0; i < argc; ++i)
256     foo();
257 #pragma omp parallel
258 #pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
259   for (i = 0; i < argc; ++i)
260     foo();
261 #pragma omp parallel
262 #pragma omp for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
263   for (i = 0; i < argc; ++i)
264     foo();
265 #pragma omp parallel
266 #pragma omp for firstprivate(i) // expected-note {{defined as firstprivate}}
267   for (i = 0; i < argc; ++i)    // expected-error {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}}
268     foo();
269 #pragma omp parallel shared(xa)
270 #pragma omp for firstprivate(xa) // OK: may be firstprivate
271   for (i = 0; i < argc; ++i)
272     foo();
273 #pragma omp parallel
274 #pragma omp for firstprivate(j)
275   for (i = 0; i < argc; ++i)
276     foo();
277 #pragma omp parallel
278 #pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
279   for (i = 0; i < argc; ++i)
280     foo();
281 #pragma omp parallel
282 #pragma omp for lastprivate(n) firstprivate(n) // OK
283   for (i = 0; i < argc; ++i)
284     foo();
285 #pragma omp parallel
286   {
287     int v = 0;
288     int i;                      // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}}
289 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
290     for (int k = 0; k < argc; ++k) {
291       i = k;
292       v += i;
293     }
294   }
295 #pragma omp parallel private(i) // expected-note {{defined as private}}
296 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
297   for (i = 0; i < argc; ++i)
298     foo();
299 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
300 #pragma omp for firstprivate(i)       // expected-error {{firstprivate variable must be shared}}
301   for (i = 0; i < argc; ++i)
302     foo();
303 #pragma omp parallel
304 #pragma omp for firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
305   for (i = 0; i < argc; ++i)
306     foo();
307   static int si;
308 #pragma omp for firstprivate(si) // OK
309   for (i = 0; i < argc; ++i)
310     si = i + 1;
311
312   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
313 }
314