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