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