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