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