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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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, z;
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 masked taskloop simd 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 masked taskloop simd in_reduction + // expected-error {{expected '(' after 'in_reduction'}} expected-warning {{extra tokens at the end of '#pragma omp masked taskloop simd' are ignored}}
141   for (int i = 0; i < 10; ++i)
142   foo();
143 #pragma omp taskgroup task_reduction(+:argc)
144 #pragma omp masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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(|:z) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
168 #pragma omp masked taskloop simd in_reduction(| : z, // 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd in_reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
207   for (int i = 0; i < 10; ++i)
208   foo();
209 #pragma omp masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd 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 masked taskloop simd allocate(omp_thread_mem_alloc: fl) in_reduction(+ : fl) // expected-warning 2 {{allocator with the 'thread' trait access has unspecified behavior on 'masked taskloop simd' 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 masked taskloop simd 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 masked taskloop simd 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, z;
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   int tid = 0;
279 #pragma omp masked taskloop simd in_reduction filter(tid) // expected-error {{expected '(' after 'in_reduction'}}
280   for (int i = 0; i < 10; ++i)
281   foo();
282 #pragma omp masked taskloop simd in_reduction + // expected-error {{expected '(' after 'in_reduction'}} expected-warning {{extra tokens at the end of '#pragma omp masked taskloop simd' are ignored}}
283   for (int i = 0; i < 10; ++i)
284   foo();
285 #pragma omp masked taskloop simd in_reduction( // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
286   for (int i = 0; i < 10; ++i)
287   foo();
288 #pragma omp masked taskloop simd in_reduction(- // expected-warning {{missing ':' after reduction identifier - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}}
289   for (int i = 0; i < 10; ++i)
290   foo();
291 #pragma omp masked taskloop simd in_reduction() // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
292   for (int i = 0; i < 10; ++i)
293   foo();
294 #pragma omp masked taskloop simd in_reduction(*) // expected-warning {{missing ':' after reduction identifier - ignoring}}
295   for (int i = 0; i < 10; ++i)
296   foo();
297 #pragma omp masked taskloop simd in_reduction(\) // expected-error {{expected unqualified-id}} expected-warning {{missing ':' after reduction identifier - ignoring}}
298   for (int i = 0; i < 10; ++i)
299   foo();
300 #pragma omp masked taskloop simd in_reduction(foo : argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max'}}
301   for (int i = 0; i < 10; ++i)
302   foo();
303 #pragma omp taskgroup task_reduction(|:argc)
304 #pragma omp masked taskloop simd in_reduction(| : argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
305   for (int i = 0; i < 10; ++i)
306   foo();
307 #pragma omp masked taskloop simd in_reduction(|| : argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name, array element or array section}}
308   for (int i = 0; i < 10; ++i)
309   foo();
310 #pragma omp masked taskloop simd in_reduction(~ : argc) // expected-error {{expected unqualified-id}}
311   for (int i = 0; i < 10; ++i)
312   foo();
313 #pragma omp taskgroup task_reduction(&&:argc, z)
314 #pragma omp masked taskloop simd in_reduction(&& : argc, z)
315   for (int i = 0; i < 10; ++i)
316   foo();
317 #pragma omp masked taskloop simd in_reduction(^ : S1) // expected-error {{'S1' does not refer to a value}}
318   for (int i = 0; i < 10; ++i)
319   foo();
320 #pragma omp taskgroup task_reduction(+:c)
321 #pragma omp masked taskloop simd 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'}}
322   for (int i = 0; i < 10; ++i)
323   foo();
324 #pragma omp masked taskloop simd 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}}
325   for (int i = 0; i < 10; ++i)
326   foo();
327 #pragma omp masked taskloop simd in_reduction(max : h.b) // expected-error {{expected variable name, array element or array section}}
328   for (int i = 0; i < 10; ++i)
329   foo();
330 #pragma omp masked taskloop simd in_reduction(+ : ba) // expected-error {{const-qualified variable cannot be in_reduction}}
331   for (int i = 0; i < 10; ++i)
332   foo();
333 #pragma omp masked taskloop simd in_reduction(* : ca) // expected-error {{const-qualified variable cannot be in_reduction}}
334   for (int i = 0; i < 10; ++i)
335   foo();
336 #pragma omp masked taskloop simd in_reduction(- : da) // expected-error {{const-qualified variable cannot be in_reduction}}
337   for (int i = 0; i < 10; ++i)
338   foo();
339 #pragma omp masked taskloop simd in_reduction(^ : fl) // expected-error {{invalid operands to binary expression ('float' and 'float')}}
340   for (int i = 0; i < 10; ++i)
341   foo();
342 #pragma omp masked taskloop simd in_reduction(&& : S2::S2s) // expected-error {{shared variable cannot be reduction}}
343   for (int i = 0; i < 10; ++i)
344   foo();
345 #pragma omp masked taskloop simd in_reduction(&& : S2::S2sc) // expected-error {{const-qualified variable cannot be in_reduction}}
346   for (int i = 0; i < 10; ++i)
347   foo();
348 #pragma omp masked taskloop simd 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')}}
349   for (int i = 0; i < 10; ++i)
350   foo();
351 #pragma omp taskgroup task_reduction(+:k)
352 #pragma omp masked taskloop simd in_reduction(+ : h, k, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be reduction}}
353   for (int i = 0; i < 10; ++i)
354   foo();
355 #pragma omp masked taskloop simd in_reduction(+ : o) // expected-error {{no viable overloaded '='}}
356   for (int i = 0; i < 10; ++i)
357   foo();
358 #pragma omp parallel private(k)
359 #pragma omp masked taskloop simd in_reduction(+ : p), in_reduction(+ : p) // expected-error 2 {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
360   for (int i = 0; i < 10; ++i)
361   foo();
362 #pragma omp taskgroup task_reduction(+:p)
363 #pragma omp masked taskloop simd in_reduction(+ : p), in_reduction(+ : p) // expected-error {{variable can appear only once in OpenMP 'in_reduction' clause}} expected-note {{previously referenced here}}
364   for (int i = 0; i < 10; ++i)
365   foo();
366 #pragma omp masked taskloop simd in_reduction(+ : r) // expected-error {{const-qualified variable cannot be in_reduction}}
367   for (int i = 0; i < 10; ++i)
368   foo();
369 #pragma omp parallel shared(i)
370 #pragma omp parallel reduction(min : i)
371 #pragma omp masked taskloop simd in_reduction(max : j) // expected-error {{argument of OpenMP clause 'in_reduction' must reference the same object in all threads}}
372   for (int i = 0; i < 10; ++i)
373   foo();
374 #pragma omp parallel
375 #pragma omp for private(fl)
376   for (int i = 0; i < 10; ++i)
377 #pragma omp taskgroup task_reduction(+:fl)
378 #pragma omp masked taskloop simd in_reduction(+ : fl)
379   for (int j = 0; j < 10; ++j)
380     foo();
381 #pragma omp taskgroup task_reduction(+:fl)
382 #pragma omp masked taskloop simd in_reduction(+ : fl)
383   for (int i = 0; i < 10; ++i)
384     foo();
385   static int m;
386 #pragma omp taskgroup task_reduction(+:m)
387 #pragma omp masked taskloop simd in_reduction(+ : m) // OK
388   for (int i = 0; i < 10; ++i)
389   m++;
390 
391   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}}
392 }
393