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