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