1 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 150 -o - %s -Wuninitialized
2 // RUN: %clang_cc1 -verify -fopenmp -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
4
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 150 -o - %s -Wuninitialized
6 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++98 -ferror-limit 150 -o - %s -Wuninitialized
7 // RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -ferror-limit 150 -o - %s -Wuninitialized
8
9 typedef void **omp_allocator_handle_t;
10 extern const omp_allocator_handle_t omp_null_allocator;
11 extern const omp_allocator_handle_t omp_default_mem_alloc;
12 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
13 extern const omp_allocator_handle_t omp_const_mem_alloc;
14 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
15 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
16 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
17 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
18 extern const omp_allocator_handle_t omp_thread_mem_alloc;
19
foo()20 void foo() {
21 }
22
foobool(int argc)23 bool foobool(int argc) {
24 return argc;
25 }
26
foobar(int & ref)27 void foobar(int &ref) {
28 #pragma omp taskgroup task_reduction(+:ref)
29 #pragma omp master taskloop in_reduction(+:ref)
30 for (int i = 0; i < 10; ++i)
31 foo();
32 }
33
foobar1(int & ref)34 void foobar1(int &ref) {
35 #pragma omp taskgroup task_reduction(+:ref)
36 #pragma omp master taskloop in_reduction(-:ref)
37 for (int i = 0; i < 10; ++i)
38 foo();
39 }
40
41 #pragma omp declare reduction (red:int:omp_out += omp_in)
42
foobar2(int & ref)43 void foobar2(int &ref) {
44 #pragma omp taskgroup task_reduction(+:ref) // expected-note {{previously marked as task_reduction with different reduction operation}}
45 #pragma omp master taskloop in_reduction(red:ref) // expected-error{{in_reduction variable must have the same reduction operation as in a task_reduction clause}}
46 for (int i = 0; i < 10; ++i)
47 foo();
48 }
49
foobar3(int & ref)50 void foobar3(int &ref) {
51 #pragma omp taskgroup task_reduction(red:ref) // expected-note {{previously marked as task_reduction with different reduction operation}}
52 #pragma omp master taskloop in_reduction(min:ref) // expected-error{{in_reduction variable must have the same reduction operation as in a task_reduction clause}}
53 for (int i = 0; i < 10; ++i)
54 foo();
55 }
56
foobar4(int & ref)57 void foobar4(int &ref) {
58 #pragma omp master taskloop in_reduction(min:ref)
59 for (int i = 0; i < 10; ++i)
60 foo();
61 }
62
63 struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
64 extern S1 a;
65 class S2 {
66 mutable int a;
operator +(const S2 & arg)67 S2 &operator+(const S2 &arg) { return (*this); } // expected-note 3 {{implicitly declared private here}}
68
69 public:
S2()70 S2() : a(0) {}
S2(S2 & s2)71 S2(S2 &s2) : a(s2.a) {}
72 static float S2s; // expected-note 2 {{static data member is predetermined as shared}}
73 static const float S2sc; // expected-note 2 {{'S2sc' declared here}}
74 };
75 const float S2::S2sc = 0;
76 S2 b; // expected-note 3 {{'b' defined here}}
77 const S2 ba[5]; // expected-note 2 {{'ba' defined here}}
78 class S3 {
79 int a;
80
81 public:
82 int b;
S3()83 S3() : a(0) {}
S3(const S3 & s3)84 S3(const S3 &s3) : a(s3.a) {}
operator +(const S3 & arg1)85 S3 operator+(const S3 &arg1) { return arg1; }
86 };
operator +(const S3 & arg1,const S3 & arg2)87 int operator+(const S3 &arg1, const S3 &arg2) { return 5; }
88 S3 c; // expected-note 3 {{'c' defined here}}
89 const S3 ca[5]; // expected-note 2 {{'ca' defined here}}
90 extern const int f; // expected-note 4 {{'f' declared here}}
91 class S4 {
92 int a;
93 S4(); // expected-note {{implicitly declared private here}}
94 S4(const S4 &s4);
operator +(const S4 & arg)95 S4 &operator+(const S4 &arg) { return (*this); }
96
97 public:
S4(int v)98 S4(int v) : a(v) {}
99 };
operator &=(S4 & arg1,S4 & arg2)100 S4 &operator&=(S4 &arg1, S4 &arg2) { return arg1; }
101 class S5 {
102 int a;
S5()103 S5() : a(0) {} // expected-note {{implicitly declared private here}}
S5(const S5 & s5)104 S5(const S5 &s5) : a(s5.a) {}
105 S5 &operator+(const S5 &arg);
106
107 public:
S5(int v)108 S5(int v) : a(v) {}
109 };
110 class S6 { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const S6' for 1st argument}}
111 #if __cplusplus >= 201103L // C++11 or later
112 // expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}
113 #endif
114 int a;
115
116 public:
S6()117 S6() : a(6) {}
operator int()118 operator int() { return 6; }
119 } o;
120
121 S3 h, k;
122 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
123
124 template <class T> // expected-note {{declared here}}
tmain(T argc)125 T tmain(T argc) {
126 const T d = T(); // expected-note 4 {{'d' defined here}}
127 const T da[5] = {T()}; // expected-note 2 {{'da' defined here}}
128 T qa[5] = {T()};
129 T i;
130 T &j = i; // expected-note 2 {{'j' defined here}}
131 S3 &p = k; // expected-note 2 {{'p' defined here}}
132 const T &r = da[(int)i]; // expected-note 2 {{'r' defined here}}
133 T &q = qa[(int)i];
134 T fl;
135 #pragma omp taskgroup task_reduction(+:argc)
136 #pragma omp master taskloop in_reduction // expected-error {{expected '(' after 'in_reduction'}}
137 for (int i = 0; i < 10; ++i)
138 foo();
139 #pragma omp taskgroup task_reduction(+:argc)
140 #pragma omp master taskloop in_reduction + // expected-error {{expected '(' after 'in_reduction'}} expected-warning {{extra tokens at the end of '#pragma omp master taskloop' are ignored}}
141 for (int i = 0; i < 10; ++i)
142 foo();
143 #pragma omp taskgroup task_reduction(+:argc)
144 #pragma omp master taskloop in_reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
145 for (int i = 0; i < 10; ++i)
146 foo();
147 #pragma omp taskgroup task_reduction(+:argc)
148 #pragma omp master taskloop in_reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
149 for (int i = 0; i < 10; ++i)
150 foo();
151 #pragma omp taskgroup task_reduction(+:argc)
152 #pragma omp master taskloop in_reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
153 for (int i = 0; i < 10; ++i)
154 foo();
155 #pragma omp taskgroup task_reduction(+:argc)
156 #pragma omp master taskloop in_reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}}
157 for (int i = 0; i < 10; ++i)
158 foo();
159 #pragma omp taskgroup task_reduction(+:argc)
160 #pragma omp master taskloop in_reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
161 for (int i = 0; i < 10; ++i)
162 foo();
163 #pragma omp taskgroup task_reduction(&:argc) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
164 #pragma omp master taskloop in_reduction(& : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
165 for (int i = 0; i < 10; ++i)
166 foo();
167 #pragma omp taskgroup task_reduction(|:argc) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
168 #pragma omp master taskloop in_reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{invalid operands to binary expression ('float' and 'float')}}
169 for (int i = 0; i < 10; ++i)
170 foo();
171 #pragma omp master taskloop in_reduction(|| : argc ? i : argc) // expected-error 2 {{expected variable name, array element or array section}}
172 for (int i = 0; i < 10; ++i)
173 foo();
174 #pragma omp master taskloop in_reduction(foo : argc) //expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'float'}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'}}
175 for (int i = 0; i < 10; ++i)
176 foo();
177 #pragma omp taskgroup task_reduction(&&:argc)
178 #pragma omp master taskloop in_reduction(&& : argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
179 for (int i = 0; i < 10; ++i)
180 foo();
181 #pragma omp master taskloop in_reduction(^ : T) // expected-error {{'T' does not refer to a value}}
182 for (int i = 0; i < 10; ++i)
183 foo();
184 #pragma omp taskgroup task_reduction(+:c)
185 #pragma omp master taskloop in_reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 3 {{const-qualified variable cannot be in_reduction}} expected-error 2 {{'operator+' is a private member of 'S2'}}
186 for (int i = 0; i < 10; ++i)
187 foo();
188 #pragma omp master taskloop in_reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 4 {{arguments of OpenMP clause 'in_reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 3 {{const-qualified variable cannot be in_reduction}}
189 for (int i = 0; i < 10; ++i)
190 foo();
191 #pragma omp master taskloop in_reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
192 for (int i = 0; i < 10; ++i)
193 foo();
194 #pragma omp master taskloop in_reduction(+ : ba) // expected-error {{const-qualified variable cannot be in_reduction}}
195 for (int i = 0; i < 10; ++i)
196 foo();
197 #pragma omp master taskloop in_reduction(* : ca) // expected-error {{const-qualified variable cannot be in_reduction}}
198 for (int i = 0; i < 10; ++i)
199 foo();
200 #pragma omp master taskloop in_reduction(- : da) // expected-error {{const-qualified variable cannot be in_reduction}} expected-error {{const-qualified variable cannot be in_reduction}}
201 for (int i = 0; i < 10; ++i)
202 foo();
203 #pragma omp master taskloop in_reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
204 for (int i = 0; i < 10; ++i)
205 foo();
206 #pragma omp master taskloop in_reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
207 for (int i = 0; i < 10; ++i)
208 foo();
209 #pragma omp master taskloop in_reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be in_reduction}}
210 for (int i = 0; i < 10; ++i)
211 foo();
212 #pragma omp taskgroup task_reduction(+:k)
213 #pragma omp master taskloop in_reduction(+ : h, k) // expected-error {{threadprivate or thread local variable cannot be reduction}}
214 for (int i = 0; i < 10; ++i)
215 foo();
216 #pragma omp master taskloop in_reduction(+ : o) // expected-error 2 {{no viable overloaded '='}}
217 for (int i = 0; i < 10; ++i)
218 foo();
219 #pragma omp parallel private(k)
220 #pragma omp master taskloop in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
221 for (int i = 0; i < 10; ++i)
222 foo();
223 #pragma omp taskgroup task_reduction(+:p)
224 #pragma omp master taskloop in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{variable can appear only once in OpenMP 'in_reduction' clause}} expected-note 2 {{previously referenced here}}
225 for (int i = 0; i < 10; ++i)
226 foo();
227 #pragma omp master taskloop in_reduction(+ : r) // expected-error 2 {{const-qualified variable cannot be in_reduction}}
228 for (int i = 0; i < 10; ++i)
229 foo();
230 #pragma omp parallel shared(i)
231 #pragma omp parallel reduction(min : i)
232 #pragma omp master taskloop in_reduction(max : j) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
233 for (int i = 0; i < 10; ++i)
234 foo();
235 #pragma omp taskgroup task_reduction(+:fl)
236 {
237 #pragma omp master taskloop in_reduction(+ : fl) allocate(omp_thread_mem_alloc: fl) // expected-warning 2 {{allocator with the 'thread' trait access has unspecified behavior on 'master taskloop' directive}}
238 for (int i = 0; i < 10; ++i)
239 foo();
240 #pragma omp taskgroup task_reduction(*:fl) // expected-note 2 {{previously marked as task_reduction with different reduction operation}}
241 {
242 #pragma omp master taskloop in_reduction(+ : fl) // expected-error 2 {{in_reduction variable must have the same reduction operation as in a task_reduction clause}}
243 for (int i = 0; i < 10; ++i)
244 foo();
245 }
246 }
247 #pragma omp parallel
248 #pragma omp for reduction(- : fl)
249 for (int i = 0; i < 10; ++i)
250 #pragma omp taskgroup task_reduction(+:fl)
251 #pragma omp master taskloop in_reduction(+ : fl)
252 for (int j = 0; j < 10; ++j)
253 foo();
254
255 return T();
256 }
257
258 namespace A {
259 double x;
260 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
261 }
262 namespace B {
263 using A::x;
264 }
265
main(int argc,char ** argv)266 int main(int argc, char **argv) {
267 const int d = 5; // expected-note 2 {{'d' defined here}}
268 const int da[5] = {0}; // expected-note {{'da' defined here}}
269 int qa[5] = {0};
270 S4 e(4);
271 S5 g(5);
272 int i;
273 int &j = i; // expected-note {{'j' defined here}}
274 S3 &p = k; // expected-note 2 {{'p' defined here}}
275 const int &r = da[i]; // expected-note {{'r' defined here}}
276 int &q = qa[i];
277 float fl;
278 #pragma omp master taskloop in_reduction // expected-error {{expected '(' after 'in_reduction'}}
279 for (int i = 0; i < 10; ++i)
280 foo();
281 #pragma omp master taskloop in_reduction + // expected-error {{expected '(' after 'in_reduction'}} expected-warning {{extra tokens at the end of '#pragma omp master taskloop' are ignored}}
282 for (int i = 0; i < 10; ++i)
283 foo();
284 #pragma omp master taskloop in_reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
285 for (int i = 0; i < 10; ++i)
286 foo();
287 #pragma omp master taskloop in_reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
288 for (int i = 0; i < 10; ++i)
289 foo();
290 #pragma omp master taskloop in_reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
291 for (int i = 0; i < 10; ++i)
292 foo();
293 #pragma omp master taskloop in_reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}}
294 for (int i = 0; i < 10; ++i)
295 foo();
296 #pragma omp master taskloop in_reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
297 for (int i = 0; i < 10; ++i)
298 foo();
299 #pragma omp master taskloop in_reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
300 for (int i = 0; i < 10; ++i)
301 foo();
302 #pragma omp taskgroup task_reduction(|:argc)
303 #pragma omp master taskloop in_reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
304 for (int i = 0; i < 10; ++i)
305 foo();
306 #pragma omp master taskloop in_reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
307 for (int i = 0; i < 10; ++i)
308 foo();
309 #pragma omp master taskloop in_reduction(~ : argc) // expected-error {{expected unqualified-id}}
310 for (int i = 0; i < 10; ++i)
311 foo();
312 #pragma omp taskgroup task_reduction(&&:argc)
313 #pragma omp master taskloop in_reduction(&& : argc)
314 for (int i = 0; i < 10; ++i)
315 foo();
316 #pragma omp master taskloop in_reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
317 for (int i = 0; i < 10; ++i)
318 foo();
319 #pragma omp taskgroup task_reduction(+:c)
320 #pragma omp master taskloop in_reduction(+ : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{const-qualified variable cannot be in_reduction}} expected-error {{'operator+' is a private member of 'S2'}}
321 for (int i = 0; i < 10; ++i)
322 foo();
323 #pragma omp master taskloop in_reduction(min : a, b, c, d, f) // expected-error {{a reduction list item with incomplete type 'S1'}} expected-error 2 {{arguments of OpenMP clause 'in_reduction' for 'min' or 'max' must be of arithmetic type}} expected-error 2 {{const-qualified variable cannot be in_reduction}}
324 for (int i = 0; i < 10; ++i)
325 foo();
326 #pragma omp master taskloop in_reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
327 for (int i = 0; i < 10; ++i)
328 foo();
329 #pragma omp master taskloop in_reduction(+ : ba) // expected-error {{const-qualified variable cannot be in_reduction}}
330 for (int i = 0; i < 10; ++i)
331 foo();
332 #pragma omp master taskloop in_reduction(* : ca) // expected-error {{const-qualified variable cannot be in_reduction}}
333 for (int i = 0; i < 10; ++i)
334 foo();
335 #pragma omp master taskloop in_reduction(- : da) // expected-error {{const-qualified variable cannot be in_reduction}}
336 for (int i = 0; i < 10; ++i)
337 foo();
338 #pragma omp master taskloop in_reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
339 for (int i = 0; i < 10; ++i)
340 foo();
341 #pragma omp master taskloop in_reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
342 for (int i = 0; i < 10; ++i)
343 foo();
344 #pragma omp master taskloop in_reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be in_reduction}}
345 for (int i = 0; i < 10; ++i)
346 foo();
347 #pragma omp master taskloop in_reduction(& : e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{nvalid operands to binary expression ('S4' and 'S4')}} expected-error {{calling a private constructor of class 'S5'}} expected-error {{invalid operands to binary expression ('S5' and 'S5')}}
348 for (int i = 0; i < 10; ++i)
349 foo();
350 #pragma omp taskgroup task_reduction(+:k)
351 #pragma omp master taskloop in_reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
352 for (int i = 0; i < 10; ++i)
353 foo();
354 #pragma omp master taskloop in_reduction(+ : o) // expected-error {{no viable overloaded '='}}
355 for (int i = 0; i < 10; ++i)
356 foo();
357 #pragma omp parallel private(k)
358 #pragma omp master taskloop in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
359 for (int i = 0; i < 10; ++i)
360 foo();
361 #pragma omp taskgroup task_reduction(+:p)
362 #pragma omp master taskloop in_reduction(+ : p), in_reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'in_reduction' clause}} expected-note {{previously referenced here}}
363 for (int i = 0; i < 10; ++i)
364 foo();
365 #pragma omp master taskloop in_reduction(+ : r) // expected-error {{const-qualified variable cannot be in_reduction}}
366 for (int i = 0; i < 10; ++i)
367 foo();
368 #pragma omp parallel shared(i)
369 #pragma omp parallel reduction(min : i)
370 #pragma omp master taskloop in_reduction(max : j) // expected-error {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
371 for (int i = 0; i < 10; ++i)
372 foo();
373 #pragma omp parallel
374 #pragma omp for private(fl)
375 for (int i = 0; i < 10; ++i)
376 #pragma omp taskgroup task_reduction(+:fl)
377 #pragma omp master taskloop in_reduction(+ : fl)
378 for (int j = 0; j < 10; ++j)
379 foo();
380 #pragma omp taskgroup task_reduction(+:fl)
381 #pragma omp master taskloop in_reduction(+ : fl)
382 for (int i = 0; i < 10; ++i)
383 foo();
384 static int m;
385 #pragma omp taskgroup task_reduction(+:m)
386 #pragma omp master taskloop in_reduction(+ : m) // OK
387 for (int i = 0; i < 10; ++i)
388 m++;
389
390 return tmain(argc) + tmain(fl); // expected-note {{in instantiation of function template specialization 'tmain<int>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<float>' requested here}}
391 }
392