Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_simd_linear_messages.cpp
blob1da49a9a5e4c4007c45e6fe5880610b69a9413fa
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2 // RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -DOMP52 %s -Wuninitialized
4 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 // RUN: %clang_cc1 -verify=expected,omp52 -fopenmp-simd -fopenmp-version=52 -DOMP52 %s -Wuninitialized
7 #pragma omp requires dynamic_allocators
9 typedef void **omp_allocator_handle_t;
10 extern const omp_allocator_handle_t omp_null_allocator;
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;
20 void xxx(int argc) {
21 int i, lin, step_sz; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step_sz' to silence this warning}}
22 #pragma omp target parallel for simd linear(i, lin : step_sz) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step_sz' is uninitialized when used here}}
23 for (i = 0; i < 10; ++i)
27 namespace X {
28 int x;
31 struct B {
32 static int ib; // expected-note {{'B::ib' declared here}}
33 static int bfoo() { return 8; }
36 int bfoo() { return 4; }
38 int z;
39 const int C1 = 1;
40 const int C2 = 2;
41 void test_linear_colons() {
42 int B = 0;
43 #pragma omp target parallel for simd linear(B : bfoo())
44 for (int i = 0; i < 10; ++i)
46 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
47 #pragma omp target parallel for simd linear(B::ib : B : bfoo())
48 for (int i = 0; i < 10; ++i)
50 // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
51 #pragma omp target parallel for simd linear(B : ib)
52 for (int i = 0; i < 10; ++i)
54 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
55 #pragma omp target parallel for simd linear(z : B : ib)
56 for (int i = 0; i < 10; ++i)
58 #pragma omp target parallel for simd linear(B : B::bfoo())
59 for (int i = 0; i < 10; ++i)
61 #pragma omp target parallel for simd linear(X::x : ::z)
62 for (int i = 0; i < 10; ++i)
64 #pragma omp target parallel for simd linear(B, ::z, X::x)
65 for (int i = 0; i < 10; ++i)
67 #pragma omp target parallel for simd linear(::z) allocate(omp_thread_mem_alloc: ::z) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target parallel for simd' directive}}
68 for (int i = 0; i < 10; ++i)
70 // expected-error@+1 {{expected variable name}}
71 #pragma omp target parallel for simd linear(B::bfoo())
72 for (int i = 0; i < 10; ++i)
74 #pragma omp target parallel for simd linear(B::ib, B : C1 + C2)
75 for (int i = 0; i < 10; ++i)
79 template <int L, class T, class N>
80 T test_template(T *arr, N num) {
81 N i;
82 T sum = (T)0;
83 T ind2 = -num * L; // expected-note {{'ind2' defined here}}
84 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
85 #pragma omp target parallel for simd linear(ind2 : L)
86 for (i = 0; i < num; ++i) {
87 T cur = arr[(int)ind2];
88 ind2 += L;
89 sum += cur;
91 return T();
94 template <int LEN>
95 int test_warn() {
96 int ind2 = 0;
97 // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
98 #pragma omp target parallel for simd linear(ind2 : LEN)
99 for (int i = 0; i < 100; i++) {
100 ind2 += LEN;
102 return ind2;
105 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
106 extern S1 a;
107 class S2 {
108 mutable int a;
110 public:
111 S2() : a(0) {}
113 const S2 b; // expected-note 2 {{'b' defined here}}
114 const S2 ba[5];
115 class S3 {
116 int a;
118 public:
119 S3() : a(0) {}
121 const S3 ca[5];
122 class S4 {
123 int a;
124 S4();
126 public:
127 S4(int v) : a(v) {}
129 class S5 {
130 int a;
131 S5() : a(0) {}
133 public:
134 S5(int v) : a(v) {}
137 S3 h;
138 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
140 template <class I, class C>
141 int foomain(I argc, C **argv) {
142 I e(4);
143 I g(5);
144 int i, z;
145 int &j = i;
146 #pragma omp target parallel for simd linear // expected-error {{expected '(' after 'linear'}}
147 for (int k = 0; k < argc; ++k)
148 ++k;
149 #pragma omp target parallel for simd linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
150 for (int k = 0; k < argc; ++k)
151 ++k;
152 #pragma omp target parallel for simd linear() // expected-error {{expected expression}}
153 for (int k = 0; k < argc; ++k)
154 ++k;
155 #pragma omp target parallel for simd linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
156 for (int k = 0; k < argc; ++k)
157 ++k;
158 #pragma omp target parallel for simd linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
159 for (int k = 0; k < argc; ++k)
160 ++k;
161 #pragma omp target parallel for simd linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
162 for (int k = 0; k < argc; ++k)
163 ++k;
164 #pragma omp target parallel for simd linear(argc : 5) 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 '('}}
165 for (int k = 0; k < argc; ++k)
166 ++k;
167 #pragma omp target parallel for simd linear(S1) // expected-error {{'S1' does not refer to a value}}
168 for (int k = 0; k < argc; ++k)
169 ++k;
170 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
171 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
172 #pragma omp target parallel for simd linear(a, b : B::ib)
173 for (int k = 0; k < argc; ++k)
174 ++k;
175 #pragma omp target parallel for simd linear(argv[1]) // expected-error {{expected variable name}}
176 for (int k = 0; k < argc; ++k)
177 ++k;
178 #pragma omp target parallel for simd linear(e, g, z)
179 for (int k = 0; k < argc; ++k)
180 ++k;
181 #pragma omp target parallel for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
182 for (int k = 0; k < argc; ++k)
183 ++k;
184 #pragma omp target parallel for simd linear(i)
185 for (int k = 0; k < argc; ++k)
186 ++k;
187 #pragma omp parallel
189 int v = 0;
190 int i;
191 #pragma omp target parallel for simd linear(v : i)
192 for (int k = 0; k < argc; ++k) {
193 i = k;
194 v += i;
197 #pragma omp target parallel for simd linear(j)
198 for (int k = 0; k < argc; ++k)
199 ++k;
200 int v = 0;
201 #pragma omp target parallel for simd linear(v : j)
202 for (int k = 0; k < argc; ++k) {
203 ++k;
204 v += j;
206 #pragma omp target parallel for simd linear(i)
207 for (int k = 0; k < argc; ++k)
208 ++k;
209 return 0;
212 namespace A {
213 double x;
214 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
216 namespace C {
217 using A::x;
220 int main(int argc, char **argv) {
221 double darr[100];
222 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
223 test_template<-4>(darr, 4);
224 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
225 test_warn<0>();
227 S4 e(4); // expected-note {{'e' defined here}}
228 S5 g(5); // expected-note {{'g' defined here}}
229 int i, z;
230 int &j = i;
231 #pragma omp target parallel for simd linear // expected-error {{expected '(' after 'linear'}}
232 for (int k = 0; k < argc; ++k)
233 ++k;
234 #pragma omp target parallel for simd linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
235 for (int k = 0; k < argc; ++k)
236 ++k;
237 #pragma omp target parallel for simd linear() // expected-error {{expected expression}}
238 for (int k = 0; k < argc; ++k)
239 ++k;
240 #pragma omp target parallel for simd linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
241 for (int k = 0; k < argc; ++k)
242 ++k;
243 #pragma omp target parallel for simd linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
244 for (int k = 0; k < argc; ++k)
245 ++k;
246 #pragma omp target parallel for simd linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
247 for (int k = 0; k < argc; ++k)
248 ++k;
249 #pragma omp target parallel for simd linear(argc, z)
250 for (int k = 0; k < argc; ++k)
251 ++k;
252 #pragma omp target parallel for simd linear(S1) // expected-error {{'S1' does not refer to a value}}
253 for (int k = 0; k < argc; ++k)
254 ++k;
255 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
256 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
257 #pragma omp target parallel for simd linear(a, b)
258 for (int k = 0; k < argc; ++k)
259 ++k;
260 #pragma omp target parallel for simd linear(argv[1]) // expected-error {{expected variable name}}
261 for (int k = 0; k < argc; ++k)
262 ++k;
263 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
264 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
265 #pragma omp target parallel for simd linear(e, g)
266 for (int k = 0; k < argc; ++k)
267 ++k;
268 #pragma omp target parallel for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
269 for (int k = 0; k < argc; ++k)
270 ++k;
271 #pragma omp parallel
273 int i;
274 #pragma omp target parallel for simd linear(i)
275 for (int k = 0; k < argc; ++k)
276 ++k;
277 #ifdef OMP52
278 #pragma omp target parallel for simd linear(i : uval, step(4)) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
279 #else
280 #pragma omp target parallel for simd linear(i : 4)
281 #endif
282 for (int k = 0; k < argc; ++k) {
283 ++k;
284 i += 4;
287 #ifdef OMP52
288 #pragma omp target parallel for simd linear(j: step() //omp52-error 2 {{expected expression}} omp52-error{{expected ')'}} omp52-note{{to match this '('}}
289 #else
290 #pragma omp target parallel for simd linear(j)
291 #endif
292 for (int k = 0; k < argc; ++k)
293 ++k;
294 #ifdef OMP52
295 #pragma omp target parallel for simd linear(i: step(1), step(2)) // omp52-error {{multiple 'step size' found in linear clause}}
296 #else
297 #pragma omp target parallel for simd linear(i)
298 #endif
299 for (int k = 0; k < argc; ++k)
300 ++k;
302 foomain<int, char>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
303 return 0;