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