Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_linear_messages.cpp
blob5a78cf0623f616d2a157a4e14859e2ff7aa93c65
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 typedef void **omp_allocator_handle_t;
8 extern const omp_allocator_handle_t omp_null_allocator;
9 extern const omp_allocator_handle_t omp_default_mem_alloc;
10 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
11 extern const omp_allocator_handle_t omp_const_mem_alloc;
12 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
13 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
14 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
15 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
16 extern const omp_allocator_handle_t omp_thread_mem_alloc;
18 void xxx(int argc) {
19 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}}
20 #pragma omp target parallel for linear(lin : step_sz) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step_sz' is uninitialized when used here}}
21 for (i = 0; i < 10; ++i)
25 namespace X {
26 int x;
29 struct B {
30 static int ib; // expected-note {{'B::ib' declared here}}
31 static int bfoo() { return 8; }
34 int bfoo() { return 4; }
36 int z;
37 const int C1 = 1;
38 const int C2 = 2;
39 void test_linear_colons() {
40 int B = 0;
41 #pragma omp target parallel for linear(B : bfoo())
42 for (int i = 0; i < 10; ++i)
44 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
45 #pragma omp target parallel for linear(B::ib : B : bfoo())
46 for (int i = 0; i < 10; ++i)
48 // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
49 #pragma omp target parallel for linear(B : ib)
50 for (int i = 0; i < 10; ++i)
52 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
53 #pragma omp target parallel for linear(z : B : ib)
54 for (int i = 0; i < 10; ++i)
56 #pragma omp target parallel for linear(B : B::bfoo())
57 for (int i = 0; i < 10; ++i)
59 #pragma omp target parallel for linear(X::x : ::z)
60 for (int i = 0; i < 10; ++i)
62 #pragma omp target parallel for linear(B, ::z, X::x)
63 for (int i = 0; i < 10; ++i)
65 #pragma omp target parallel for linear(::z)
66 for (int i = 0; i < 10; ++i)
68 // expected-error@+1 {{expected variable name}}
69 #pragma omp target parallel for linear(B::bfoo())
70 for (int i = 0; i < 10; ++i)
72 #pragma omp target parallel for linear(B::ib, B : C1 + C2)
73 for (int i = 0; i < 10; ++i)
77 template <int L, class T, class N>
78 T test_template(T *arr, N num) {
79 N i;
80 T sum = (T)0;
81 T ind2 = -num * L; // expected-note {{'ind2' defined here}}
82 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
83 #pragma omp target parallel for linear(ind2 : L)
84 for (i = 0; i < num; ++i) {
85 T cur = arr[(int)ind2];
86 ind2 += L;
87 sum += cur;
89 return T();
92 template <int LEN>
93 int test_warn() {
94 int ind2 = 0;
95 // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
96 #pragma omp target parallel for linear(ind2 : LEN)
97 for (int i = 0; i < 100; i++) {
98 ind2 += LEN;
100 return ind2;
103 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
104 extern S1 a;
105 class S2 {
106 mutable int a;
108 public:
109 S2() : a(0) {}
111 const S2 b; // expected-note 2 {{'b' defined here}}
112 const S2 ba[5];
113 class S3 {
114 int a;
116 public:
117 S3() : a(0) {}
119 const S3 ca[5];
120 class S4 {
121 int a;
122 S4();
124 public:
125 S4(int v) : a(v) {}
127 class S5 {
128 int a;
129 S5() : a(0) {}
131 public:
132 S5(int v) : a(v) {}
135 S3 h;
136 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
138 template <class I, class C>
139 int foomain(I argc, C **argv) {
140 I e(4);
141 I g(5);
142 int i, z;
143 int &j = i;
144 #pragma omp target parallel for linear // expected-error {{expected '(' after 'linear'}}
145 for (int k = 0; k < argc; ++k)
146 ++k;
147 #pragma omp target parallel for linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
148 for (int k = 0; k < argc; ++k)
149 ++k;
150 #pragma omp target parallel for linear() // expected-error {{expected expression}}
151 for (int k = 0; k < argc; ++k)
152 ++k;
153 #pragma omp target parallel for linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
154 for (int k = 0; k < argc; ++k)
155 ++k;
156 #pragma omp target parallel for linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
157 for (int k = 0; k < argc; ++k)
158 ++k;
159 #pragma omp target parallel for linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
160 for (int k = 0; k < argc; ++k)
161 ++k;
162 #pragma omp target parallel for 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 '('}}
163 for (int k = 0; k < argc; ++k)
164 ++k;
165 #pragma omp target parallel for linear(S1) // expected-error {{'S1' does not refer to a value}}
166 for (int k = 0; k < argc; ++k)
167 ++k;
168 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
169 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
170 #pragma omp target parallel for linear(a, b : B::ib)
171 for (int k = 0; k < argc; ++k)
172 ++k;
173 #pragma omp target parallel for linear(argv[1]) // expected-error {{expected variable name}}
174 for (int k = 0; k < argc; ++k)
175 ++k;
176 #pragma omp target parallel for allocate(omp_thread_mem_alloc: e) linear(e, g) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target parallel for' directive}} expected-error {{allocator must be specified in the 'uses_allocators' clause}}
177 for (int k = 0; k < argc; ++k)
178 ++k;
179 #pragma omp target parallel for linear(z, h) // expected-error {{threadprivate or thread local variable cannot be linear}}
180 for (int k = 0; k < argc; ++k)
181 ++k;
182 #pragma omp target parallel for linear(i)
183 for (int k = 0; k < argc; ++k)
184 ++k;
185 #pragma omp parallel
187 int v = 0;
188 int i;
189 #pragma omp target parallel for linear(v : i)
190 for (int k = 0; k < argc; ++k) {
191 i = k;
192 v += i;
195 #pragma omp target parallel for linear(j)
196 for (int k = 0; k < argc; ++k)
197 ++k;
198 int v = 0;
199 #pragma omp target parallel for linear(v : j)
200 for (int k = 0; k < argc; ++k) {
201 ++k;
202 v += j;
204 #pragma omp target parallel for linear(i)
205 for (int k = 0; k < argc; ++k)
206 ++k;
207 return 0;
210 namespace A {
211 double x;
212 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
214 namespace C {
215 using A::x;
218 int main(int argc, char **argv) {
219 double darr[100];
220 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
221 test_template<-4>(darr, 4);
222 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
223 test_warn<0>();
225 S4 e(4); // expected-note {{'e' defined here}}
226 S5 g(5); // expected-note {{'g' defined here}}
227 int i, z;
228 int &j = i;
229 #pragma omp target parallel for linear // expected-error {{expected '(' after 'linear'}}
230 for (int k = 0; k < argc; ++k)
231 ++k;
232 #pragma omp target parallel for linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
233 for (int k = 0; k < argc; ++k)
234 ++k;
235 #pragma omp target parallel for linear() // expected-error {{expected expression}}
236 for (int k = 0; k < argc; ++k)
237 ++k;
238 #pragma omp target parallel for linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
239 for (int k = 0; k < argc; ++k)
240 ++k;
241 #pragma omp target parallel for linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
242 for (int k = 0; k < argc; ++k)
243 ++k;
244 #pragma omp target parallel for linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
245 for (int k = 0; k < argc; ++k)
246 ++k;
247 #pragma omp target parallel for linear(argc, z)
248 for (int k = 0; k < argc; ++k)
249 ++k;
250 #pragma omp target parallel for linear(S1) // expected-error {{'S1' does not refer to a value}}
251 for (int k = 0; k < argc; ++k)
252 ++k;
253 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
254 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
255 #pragma omp target parallel for linear(a, b)
256 for (int k = 0; k < argc; ++k)
257 ++k;
258 #pragma omp target parallel for linear(argv[1]) // expected-error {{expected variable name}}
259 for (int k = 0; k < argc; ++k)
260 ++k;
261 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
262 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
263 #pragma omp target parallel for linear(e, g)
264 for (int k = 0; k < argc; ++k)
265 ++k;
266 #pragma omp target parallel for linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
267 for (int k = 0; k < argc; ++k)
268 ++k;
269 #pragma omp parallel
271 int i;
272 #pragma omp target parallel for linear(i)
273 for (int k = 0; k < argc; ++k)
274 ++k;
275 #ifdef OMP52
276 #pragma omp target parallel for linear(i : uval, step(4)) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
277 #else
278 #pragma omp target parallel for linear(i : 4)
279 #endif
280 for (int k = 0; k < argc; ++k) {
281 ++k;
282 i += 4;
285 #ifdef OMP52
286 #pragma omp target parallel for linear(j: step() //omp52-error 2 {{expected expression}} omp52-error{{expected ')'}} omp52-note{{to match this '('}}
287 #else
288 #pragma omp target parallel for linear(j)
289 #endif
290 for (int k = 0; k < argc; ++k)
291 ++k;
292 #ifdef OMP52
293 #pragma omp target parallel for linear(i: step(1), step(2)) // omp52-error {{multiple 'step size' found in linear clause}}
294 #else
295 #pragma omp target parallel for linear(i)
296 #endif
297 for (int k = 0; k < argc; ++k)
298 ++k;
300 foomain<int, char>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
301 return 0;