blob: 425125c11a09ff900da2dd17f720c9add04b3d00 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00005void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
16
17public:
18 S2() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000019 S2(const S2 &s2) : a(s2.a) {}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000020 static float S2s;
21 static const float S2sc;
22};
23const float S2::S2sc = 0;
24const S2 b;
25const S2 ba[5];
26class S3 {
27 int a;
28 S3 &operator=(const S3 &s3);
29
30public:
31 S3() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000032 S3(const S3 &s3) : a(s3.a) {}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000033};
34const S3 c;
35const S3 ca[5];
36extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000037class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000038 int a;
39 S4();
Alexey Bataev4a5bb772014-10-08 14:01:46 +000040 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000041
42public:
43 S4(int v) : a(v) {}
44};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000045class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000046 int a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000047 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000048
49public:
50 S5() : a(0) {}
51 S5(int v) : a(v) {}
52};
53class S6 {
54 int a;
55 S6() : a(0) {}
56
57public:
58 S6(const S6 &s6) : a(s6.a) {}
59 S6(int v) : a(v) {}
60};
61
62S3 h;
63#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
64
65template <class I, class C>
66int foomain(int argc, char **argv) {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000067 I e(4);
68 C g(5);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000069 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000070 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000071#pragma omp parallel
72#pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
73 {
74 foo();
75 }
76#pragma omp parallel
77#pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
78 {
79 foo();
80 }
81#pragma omp parallel
82#pragma omp sections firstprivate() // expected-error {{expected expression}}
83 {
84 foo();
85 }
86#pragma omp parallel
87#pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
88 {
89 foo();
90 }
91#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +000092#pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000093 {
94 foo();
95 }
96#pragma omp parallel
97#pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
98 {
99 foo();
100 }
101#pragma omp parallel
102#pragma omp sections firstprivate(argc)
103 {
104 foo();
105 }
106#pragma omp parallel
107#pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
108 {
109 foo();
110 }
111#pragma omp parallel
112#pragma omp sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
113 {
114 foo();
115 }
116#pragma omp parallel
117#pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
118 {
119 foo();
120 }
121#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000122#pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000123 {
124 foo();
125 }
126#pragma omp parallel
127#pragma omp sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
128 {
129 foo();
130 }
131#pragma omp parallel
132#pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
133 {
134 foo();
135 }
136#pragma omp parallel
137 {
138 int v = 0;
139 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000140#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000141 {
142 foo();
143 }
144 v += i;
145 }
146#pragma omp parallel shared(i)
147#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000148#pragma omp sections firstprivate(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000149 {
150 foo();
151 }
152#pragma omp parallel
153#pragma omp sections firstprivate(i)
154 {
155 foo();
156 }
157#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000158#pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000159 {
160 foo();
161 }
162#pragma omp parallel private(i) // expected-note {{defined as private}}
163#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
164 {
165 foo();
166 }
167#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
168#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
169 {
170 foo();
171 }
172 return 0;
173}
174
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000175namespace A {
176double x;
177#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
178}
179namespace B {
180using A::x;
181}
182
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000183int main(int argc, char **argv) {
184 const int d = 5;
185 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000186 S4 e(4);
187 S5 g(5);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000188 S3 m;
189 S6 n(2);
190 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000191 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000192#pragma omp parallel
193#pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
194 {
195 foo();
196 }
197#pragma omp parallel
198#pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
199 {
200 foo();
201 }
202#pragma omp parallel
203#pragma omp sections firstprivate() // expected-error {{expected expression}}
204 {
205 foo();
206 }
207#pragma omp parallel
208#pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
209 {
210 foo();
211 }
212#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +0000213#pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000214 {
215 foo();
216 }
217#pragma omp parallel
218#pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
219 {
220 foo();
221 }
222#pragma omp parallel
223#pragma omp sections firstprivate(argc)
224 {
225 foo();
226 }
227#pragma omp parallel
228#pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
229 {
230 foo();
231 }
232#pragma omp parallel
233#pragma omp sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
234 {
235 foo();
236 }
237#pragma omp parallel
238#pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}}
239 {
240 foo();
241 }
242#pragma omp parallel
243#pragma omp sections firstprivate(2 * 2) // expected-error {{expected variable name}}
244 {
245 foo();
246 }
247#pragma omp parallel
248#pragma omp sections firstprivate(ba) // OK
249 {
250 foo();
251 }
252#pragma omp parallel
253#pragma omp sections firstprivate(ca) // OK
254 {
255 foo();
256 }
257#pragma omp parallel
258#pragma omp sections firstprivate(da) // OK
259 {
260 foo();
261 }
262 int xa;
263#pragma omp parallel
264#pragma omp sections firstprivate(xa) // OK
265 {
266 foo();
267 }
268#pragma omp parallel
269#pragma omp sections firstprivate(S2::S2s) // OK
270 {
271 foo();
272 }
273#pragma omp parallel
274#pragma omp sections firstprivate(S2::S2sc) // OK
275 {
276 foo();
277 }
278#pragma omp parallel
279#pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
280 {
281 foo();
282 }
283#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000284#pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000285 {
286 foo();
287 }
288#pragma omp parallel
289#pragma omp sections firstprivate(m) // OK
290 {
291 foo();
292 }
293#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000294#pragma omp sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000295 {
296 foo();
297 }
298#pragma omp parallel
299#pragma omp sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
300 {
301 foo();
302 }
303#pragma omp parallel shared(xa)
304#pragma omp sections firstprivate(xa) // OK: may be firstprivate
305 {
306 foo();
307 }
308#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000309#pragma omp sections firstprivate(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000310 {
311 foo();
312 }
313#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000314#pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000315 {
316 foo();
317 }
318#pragma omp parallel
319#pragma omp sections lastprivate(n) firstprivate(n) // OK
320 {
321 foo();
322 }
323#pragma omp parallel
324 {
325 int v = 0;
326 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000327#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000328 {
329 foo();
330 }
331 v += i;
332 }
333#pragma omp parallel private(i) // expected-note {{defined as private}}
334#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
335 {
336 foo();
337 }
338#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
339#pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}}
340 {
341 foo();
342 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000343 static int r;
344#pragma omp sections firstprivate(r) // OK
345 {
346 foo();
347 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000348
349 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
350}