blob: f8370f26b4d409b70cd7d8b49c6a77f77c083468 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Alexey Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +000033};
34const S3 c;
35const S3 ca[5];
36extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000037class S4 {
Alexey Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +000041
42public:
43 S4(int v) : a(v) {}
44};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000045class S5 {
Alexey Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +000069 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000070 int &j = i;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000071#pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
72 {
73 foo();
74 }
75#pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
76 {
77 foo();
78 }
79#pragma omp parallel sections firstprivate() // expected-error {{expected expression}}
80 {
81 foo();
82 }
83#pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
84 {
85 foo();
86 }
Alexey Bataevc5970622016-04-01 08:43:42 +000087#pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000088 {
89 foo();
90 }
91#pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
92 {
93 foo();
94 }
95#pragma omp parallel sections firstprivate(argc)
96 {
97 foo();
98 }
99#pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
100 {
101 foo();
102 }
103#pragma omp parallel sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
104 {
105 foo();
106 }
107#pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}}
108 {
109 foo();
110 }
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000111#pragma omp parallel sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000112 {
113 foo();
114 }
115#pragma omp parallel sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
116 {
117 foo();
118 }
119#pragma omp parallel sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel sections'}}
120 {
121 foo();
122 }
123#pragma omp parallel
124 {
125 int v = 0;
126 int i;
127#pragma omp parallel sections firstprivate(i)
128 {
129 foo();
130 }
131 v += i;
132 }
133#pragma omp parallel shared(i)
134#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000135#pragma omp parallel sections firstprivate(j)
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000136 {
137 foo();
138 }
139#pragma omp parallel sections firstprivate(i)
140 {
141 foo();
142 }
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000143#pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000144 {
145 foo();
146 }
147#pragma omp parallel private(i)
148#pragma omp parallel sections firstprivate(i)
149 {
150 foo();
151 }
152#pragma omp parallel reduction(+ : i)
153#pragma omp parallel sections firstprivate(i)
154 {
155 foo();
156 }
157 return 0;
158}
159
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000160namespace A {
161double x;
162#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
163}
164namespace B {
165using A::x;
166}
167
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000168int main(int argc, char **argv) {
169 const int d = 5;
170 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000171 S4 e(4);
172 S5 g(5);
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000173 S3 m;
174 S6 n(2);
175 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000176 int &j = i;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000177#pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
178 {
179 foo();
180 }
181#pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
182 {
183 foo();
184 }
185#pragma omp parallel sections firstprivate() // expected-error {{expected expression}}
186 {
187 foo();
188 }
189#pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
190 {
191 foo();
192 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000193#pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000194 {
195 foo();
196 }
197#pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
198 {
199 foo();
200 }
201#pragma omp parallel sections firstprivate(argc)
202 {
203 foo();
204 }
205#pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
206 {
207 foo();
208 }
209#pragma omp parallel sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
210 {
211 foo();
212 }
213#pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}}
214 {
215 foo();
216 }
217#pragma omp parallel sections firstprivate(2 * 2) // expected-error {{expected variable name}}
218 {
219 foo();
220 }
221#pragma omp parallel sections firstprivate(ba) // OK
222 {
223 foo();
224 }
225#pragma omp parallel sections firstprivate(ca) // OK
226 {
227 foo();
228 }
229#pragma omp parallel sections firstprivate(da) // OK
230 {
231 foo();
232 }
233 int xa;
234#pragma omp parallel sections firstprivate(xa) // OK
235 {
236 foo();
237 }
238#pragma omp parallel sections firstprivate(S2::S2s) // OK
239 {
240 foo();
241 }
242#pragma omp parallel sections firstprivate(S2::S2sc) // OK
243 {
244 foo();
245 }
246#pragma omp parallel sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel sections'}}
247 {
248 foo();
249 }
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000250#pragma omp parallel sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000251 {
252 foo();
253 }
254#pragma omp parallel sections firstprivate(m) // OK
255 {
256 foo();
257 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000258#pragma omp parallel sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000259 {
260 foo();
261 }
262#pragma omp parallel sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
263 {
264 foo();
265 }
266#pragma omp parallel shared(xa)
267#pragma omp parallel sections firstprivate(xa) // OK: may be firstprivate
268 {
269 foo();
270 }
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000271#pragma omp parallel sections firstprivate(j)
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000272 {
273 foo();
274 }
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000275#pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000276 {
277 foo();
278 }
279#pragma omp parallel sections lastprivate(n) firstprivate(n) // OK
280 {
281 foo();
282 }
283#pragma omp parallel
284 {
285 int v = 0;
286 int i;
287#pragma omp parallel sections firstprivate(i)
288 {
289 foo();
290 }
291 v += i;
292 }
293#pragma omp parallel private(i)
294#pragma omp parallel sections firstprivate(i)
295 {
296 foo();
297 }
298#pragma omp parallel reduction(+ : i)
299#pragma omp parallel sections firstprivate(i)
300 {
301 foo();
302 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000303 static int r;
304#pragma omp parallel sections firstprivate(r) // OK
305 {
306 foo();
307 }
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000308
309 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
310}