blob: 1933de25850e6f734437955ee245a9ed2c21e830 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevf29276e2014-06-18 04:14:57 +00002
3void foo() {
4}
5
6bool foobool(int argc) {
7 return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13 mutable int a;
14
15public:
16 S2() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000017 S2(const S2 &s2) : a(s2.a) {}
Alexey Bataevf29276e2014-06-18 04:14:57 +000018 static float S2s;
19 static const float S2sc;
20};
21const float S2::S2sc = 0;
22const S2 b;
23const S2 ba[5];
24class S3 {
25 int a;
26 S3 &operator=(const S3 &s3);
27
28public:
Alexey Bataev69c62a92015-04-15 04:52:20 +000029 S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
30 S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000031};
32const S3 c;
33const S3 ca[5];
34extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000035class S4 {
Alexey Bataevf29276e2014-06-18 04:14:57 +000036 int a;
37 S4();
Alexey Bataev5129d3a2015-05-21 09:47:46 +000038 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000039
40public:
41 S4(int v) : a(v) {}
42};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000043class S5 {
Alexey Bataevf29276e2014-06-18 04:14:57 +000044 int a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000045 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000046
47public:
48 S5() : a(0) {}
49 S5(int v) : a(v) {}
50};
51class S6 {
52 int a;
53 S6() : a(0) {}
54
55public:
56 S6(const S6 &s6) : a(s6.a) {}
57 S6(int v) : a(v) {}
58};
59
60S3 h;
61#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
62
63template <class I, class C>
64int foomain(int argc, char **argv) {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000065 I e(4);
66 C g(5);
Alexey Bataevf29276e2014-06-18 04:14:57 +000067 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000068 int &j = i;
Alexey Bataevf29276e2014-06-18 04:14:57 +000069#pragma omp parallel
70#pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
71 for (int k = 0; k < argc; ++k)
72 ++k;
73#pragma omp parallel
74#pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
75 for (int k = 0; k < argc; ++k)
76 ++k;
77#pragma omp parallel
78#pragma omp for firstprivate() // expected-error {{expected expression}}
79 for (int k = 0; k < argc; ++k)
80 ++k;
81#pragma omp parallel
82#pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
83 for (int k = 0; k < argc; ++k)
84 ++k;
85#pragma omp parallel
86#pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
87 for (int k = 0; k < argc; ++k)
88 ++k;
89#pragma omp parallel
90#pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
91 for (int k = 0; k < argc; ++k)
92 ++k;
93#pragma omp parallel
94#pragma omp for firstprivate(argc)
95 for (int k = 0; k < argc; ++k)
96 ++k;
97#pragma omp parallel
98#pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
99 for (int k = 0; k < argc; ++k)
100 ++k;
101#pragma omp parallel
102#pragma omp for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
103 for (int k = 0; k < argc; ++k)
104 ++k;
105#pragma omp parallel
106#pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}}
107 for (int k = 0; k < argc; ++k)
108 ++k;
109#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000110#pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000111 for (int k = 0; k < argc; ++k)
112 ++k;
113#pragma omp parallel
114#pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
115 for (int k = 0; k < argc; ++k)
116 ++k;
117#pragma omp parallel
Alexey Bataevf29276e2014-06-18 04:14:57 +0000118 {
119 int v = 0;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000120 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?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000121#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000122 for (int k = 0; k < argc; ++k) {
123 i = k;
124 v += i;
125 }
126 }
127#pragma omp parallel shared(i)
128#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000129#pragma omp for firstprivate(j)
Alexey Bataevf29276e2014-06-18 04:14:57 +0000130 for (int k = 0; k < argc; ++k)
131 ++k;
132#pragma omp parallel
133#pragma omp for firstprivate(i)
134 for (int k = 0; k < argc; ++k)
135 ++k;
136#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000137#pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000138 for (i = 0; i < argc; ++i)
139 foo();
140#pragma omp parallel private(i) // expected-note {{defined as private}}
141#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
142 for (i = 0; i < argc; ++i)
143 foo();
144#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000145#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000146 for (i = 0; i < argc; ++i)
147 foo();
148 return 0;
149}
150
Alexey Bataevf120c0d2015-05-19 07:46:42 +0000151void bar(S4 a[2]) {
152#pragma omp parallel
Alexey Bataev5129d3a2015-05-21 09:47:46 +0000153#pragma omp for firstprivate(a)
Alexey Bataevf120c0d2015-05-19 07:46:42 +0000154 for (int i = 0; i < 2; ++i)
155 foo();
156}
157
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000158namespace A {
159double x;
160#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
161}
162namespace B {
163using A::x;
164}
165
Alexey Bataevf29276e2014-06-18 04:14:57 +0000166int main(int argc, char **argv) {
167 const int d = 5;
168 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000169 S4 e(4);
170 S5 g(5);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000171 S3 m;
172 S6 n(2);
173 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000174 int &j = i;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000175#pragma omp parallel
176#pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
177 for (i = 0; i < argc; ++i)
178 foo();
179#pragma omp parallel
180#pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181 for (i = 0; i < argc; ++i)
182 foo();
183#pragma omp parallel
184#pragma omp for firstprivate() // expected-error {{expected expression}}
185 for (i = 0; i < argc; ++i)
186 foo();
187#pragma omp parallel
188#pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
189 for (i = 0; i < argc; ++i)
190 foo();
191#pragma omp parallel
192#pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
193 for (i = 0; i < argc; ++i)
194 foo();
195#pragma omp parallel
196#pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
197 for (i = 0; i < argc; ++i)
198 foo();
199#pragma omp parallel
200#pragma omp for firstprivate(argc)
201 for (i = 0; i < argc; ++i)
202 foo();
203#pragma omp parallel
204#pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
205 for (i = 0; i < argc; ++i)
206 foo();
207#pragma omp parallel
Alexey Bataev69c62a92015-04-15 04:52:20 +0000208#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'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000209 for (i = 0; i < argc; ++i)
210 foo();
211#pragma omp parallel
212#pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}}
213 for (i = 0; i < argc; ++i)
214 foo();
215#pragma omp parallel
216#pragma omp for firstprivate(2 * 2) // expected-error {{expected variable name}}
217 for (i = 0; i < argc; ++i)
218 foo();
219#pragma omp parallel
220#pragma omp for firstprivate(ba) // OK
221 for (i = 0; i < argc; ++i)
222 foo();
223#pragma omp parallel
Alexey Bataev69c62a92015-04-15 04:52:20 +0000224#pragma omp for firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000225 for (i = 0; i < argc; ++i)
226 foo();
227#pragma omp parallel
228#pragma omp for firstprivate(da) // OK
229 for (i = 0; i < argc; ++i)
230 foo();
231 int xa;
232#pragma omp parallel
233#pragma omp for firstprivate(xa) // OK
234 for (i = 0; i < argc; ++i)
235 foo();
236#pragma omp parallel
237#pragma omp for firstprivate(S2::S2s) // OK
238 for (i = 0; i < argc; ++i)
239 foo();
240#pragma omp parallel
241#pragma omp for firstprivate(S2::S2sc) // OK
242 for (i = 0; i < argc; ++i)
243 foo();
244#pragma omp parallel
245#pragma omp for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp for'}}
246 for (i = 0; i < argc; ++i)
247 foo();
248#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000249#pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000250 for (i = 0; i < argc; ++i)
251 foo();
252#pragma omp parallel
253#pragma omp for firstprivate(m) // OK
254 for (i = 0; i < argc; ++i)
255 foo();
256#pragma omp parallel
257#pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
258 for (i = 0; i < argc; ++i)
259 foo();
260#pragma omp parallel
261#pragma omp for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
262 for (i = 0; i < argc; ++i)
263 foo();
264#pragma omp parallel
265#pragma omp for firstprivate(i) // expected-note {{defined as firstprivate}}
Alexey Bataev4acb8592014-07-07 13:01:15 +0000266 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}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000267 foo();
268#pragma omp parallel shared(xa)
269#pragma omp for firstprivate(xa) // OK: may be firstprivate
270 for (i = 0; i < argc; ++i)
271 foo();
272#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000273#pragma omp for firstprivate(j)
Alexey Bataevf29276e2014-06-18 04:14:57 +0000274 for (i = 0; i < argc; ++i)
275 foo();
276#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000277#pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000278 for (i = 0; i < argc; ++i)
279 foo();
280#pragma omp parallel
281#pragma omp for lastprivate(n) firstprivate(n) // OK
282 for (i = 0; i < argc; ++i)
283 foo();
284#pragma omp parallel
285 {
286 int v = 0;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000287 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?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000288#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000289 for (int k = 0; k < argc; ++k) {
290 i = k;
291 v += i;
292 }
293 }
294#pragma omp parallel private(i) // expected-note {{defined as private}}
295#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
296 for (i = 0; i < argc; ++i)
297 foo();
298#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000299#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000300 for (i = 0; i < argc; ++i)
301 foo();
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000302#pragma omp parallel
303#pragma omp for firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
304 for (i = 0; i < argc; ++i)
305 foo();
Kelvin Li4eea8c62015-09-15 18:56:58 +0000306 static int si;
307#pragma omp for firstprivate(si) // OK
308 for (i = 0; i < argc; ++i)
309 si = i + 1;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000310
311 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
312}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000313