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