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