[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / teams_distribute_parallel_for_simd_linear_messages.cpp
blob8e3864ba5e2a4d2dca9a10a1e79562385114b5a5
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 extern int omp_default_mem_alloc;
8 void xxx(int argc) {
9 int i, step_sz; // expected-note {{initialize the variable 'step_sz' to silence this warning}}
10 #pragma omp target
11 #pragma omp teams distribute parallel for simd linear(i : step_sz) // expected-warning {{variable 'step_sz' is uninitialized when used here}}
12 for (i = 0; i < 10; ++i)
16 namespace X {
17 int x;
20 struct B {
21 static int ib; // expected-note {{'B::ib' declared here}}
22 static int bfoo() { return 8; }
25 int bfoo() { return 4; }
27 int z;
28 const int C1 = 1;
29 const int C2 = 2;
30 void test_linear_colons()
32 int B = 0;
34 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
35 #pragma omp target
36 #pragma omp teams distribute parallel for simd linear(B:bfoo())
37 for (int i = 0; i < 10; ++i) ;
39 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
40 #pragma omp target
41 #pragma omp teams distribute parallel for simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
42 for (int i = 0; i < 10; ++i) ;
44 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
45 #pragma omp target
46 #pragma omp teams distribute parallel for simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
47 for (int i = 0; i < 10; ++i) ;
49 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
50 #pragma omp target
51 #pragma omp teams distribute parallel for simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
52 for (int i = 0; i < 10; ++i) ;
54 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
55 #pragma omp target
56 #pragma omp teams distribute parallel for simd linear(B:B::bfoo())
57 for (int i = 0; i < 10; ++i) ;
59 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
60 #pragma omp target
61 #pragma omp teams distribute parallel for simd linear(X::x : ::z)
62 for (int i = 0; i < 10; ++i) ;
64 // expected-error@+2 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
65 #pragma omp target
66 #pragma omp teams distribute parallel for simd linear(B,::z, X::x)
67 for (int i = 0; i < 10; ++i) ;
69 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
70 #pragma omp target
71 #pragma omp teams distribute parallel for simd linear(::z)
72 for (int i = 0; i < 10; ++i) ;
74 #pragma omp target
75 #pragma omp teams distribute parallel for simd linear(B::bfoo()) // expected-error {{expected variable name}}
76 for (int i = 0; i < 10; ++i) ;
78 // expected-error@+2 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
79 #pragma omp target
80 #pragma omp teams distribute parallel for simd linear(B::ib,B:C1+C2)
81 for (int i = 0; i < 10; ++i) ;
84 template<int L, class T, class N> T test_template(T* arr, N num) {
85 N i;
86 T sum = (T)0;
87 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
89 #pragma omp target
90 #pragma omp teams distribute parallel for simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
91 for (i = 0; i < num; ++i) {
92 T cur = arr[(int)ind2];
93 ind2 += L;
94 sum += cur;
96 return T();
99 template<int LEN> int test_warn() {
100 int ind2 = 0;
101 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
102 #pragma omp target
103 #pragma omp teams distribute parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
104 for (int i = 0; i < 100; i++) {
105 ind2 += LEN;
107 return ind2;
110 struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
111 extern S1 a;
112 class S2 {
113 mutable int a;
114 public:
115 S2():a(0) { }
117 const S2 b; // expected-note 2 {{'b' defined here}}
118 const S2 ba[5];
119 class S3 {
120 int a;
121 public:
122 S3():a(0) { }
124 const S3 ca[5];
125 class S4 {
126 int a;
127 S4();
128 public:
129 S4(int v):a(v) { }
131 class S5 {
132 int a;
133 S5():a(0) {}
134 public:
135 S5(int v):a(v) { }
138 S3 h;
139 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
141 template<class I, class C> int foomain(I argc, C **argv) {
142 I e(4);
143 I g(5);
144 int i;
145 int &j = i;
147 #pragma omp target
148 #pragma omp teams distribute parallel for simd linear // expected-error {{expected '(' after 'linear'}}
149 for (int k = 0; k < argc; ++k) ++k;
151 #pragma omp target
152 #pragma omp teams distribute parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
153 for (int k = 0; k < argc; ++k) ++k;
155 #pragma omp target
156 #pragma omp teams distribute parallel for simd linear () // expected-error {{expected expression}}
157 for (int k = 0; k < argc; ++k) ++k;
159 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
160 #pragma omp target
161 #pragma omp teams distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
162 for (int k = 0; k < argc; ++k) ++k;
164 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
165 #pragma omp target
166 #pragma omp teams distribute parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
167 for (int k = 0; k < argc; ++k) ++k;
169 #pragma omp target
170 #pragma omp teams distribute parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
171 for (int k = 0; k < argc; ++k) ++k;
173 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
174 #pragma omp target
175 #pragma omp teams distribute 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 '('}}
176 for (int k = 0; k < argc; ++k) ++k;
178 #pragma omp target
179 #pragma omp teams distribute parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
180 for (int k = 0; k < argc; ++k) ++k;
182 #pragma omp target
183 #pragma omp teams distribute parallel for simd linear (a, b:B::ib) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
184 for (int k = 0; k < argc; ++k) ++k;
186 #pragma omp target
187 #pragma omp teams distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
188 for (int k = 0; k < argc; ++k) ++k;
190 // expected-error@+2 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
191 #pragma omp target
192 #pragma omp teams distribute parallel for simd linear(e, g)
193 for (int k = 0; k < argc; ++k) ++k;
195 #pragma omp target
196 #pragma omp teams distribute parallel for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
197 for (int k = 0; k < argc; ++k) ++k;
199 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
200 #pragma omp target
201 #pragma omp teams distribute parallel for simd linear(i)
202 for (int k = 0; k < argc; ++k) ++k;
204 return 0;
207 namespace A {
208 double x;
209 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
211 namespace C {
212 using A::x;
215 int main(int argc, char **argv) {
216 double darr[100];
217 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
218 test_template<-4>(darr, 4);
219 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
220 test_warn<0>();
222 S4 e(4); // expected-note {{'e' defined here}}
223 S5 g(5); // expected-note {{'g' defined here}}
224 int i;
225 int &j = i;
227 #pragma omp target
228 #pragma omp teams distribute parallel for simd linear // expected-error {{expected '(' after 'linear'}}
229 for (int k = 0; k < argc; ++k) ++k;
231 #pragma omp target
232 #pragma omp teams distribute parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
233 for (int k = 0; k < argc; ++k) ++k;
235 #pragma omp target
236 #pragma omp teams distribute parallel for simd linear () // expected-error {{expected expression}}
237 for (int k = 0; k < argc; ++k) ++k;
239 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
240 #pragma omp target
241 #pragma omp teams distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
242 for (int k = 0; k < argc; ++k) ++k;
244 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
245 #pragma omp target
246 #pragma omp teams distribute parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
247 for (int k = 0; k < argc; ++k) ++k;
249 #pragma omp target
250 #pragma omp teams distribute parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
251 for (int k = 0; k < argc; ++k) ++k;
253 // expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
254 #pragma omp target
255 #pragma omp teams distribute parallel for simd linear (argc)
256 for (int k = 0; k < argc; ++k) ++k;
258 #pragma omp target
259 #pragma omp teams distribute parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
260 for (int k = 0; k < argc; ++k) ++k;
263 #pragma omp target
264 #pragma omp teams distribute parallel for simd linear (a, b) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S2'}} expected-error {{incomplete type 'S1' where a complete type is required}}
265 for (int k = 0; k < argc; ++k) ++k;
267 #pragma omp target
268 #pragma omp teams distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
269 for (int k = 0; k < argc; ++k) ++k;
271 #pragma omp target
272 #pragma omp teams distribute parallel for simd linear(e, g) // expected-error {{argument of a linear clause should be of integral or pointer type, not 'S4'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
273 for (int k = 0; k < argc; ++k) ++k;
275 #pragma omp target
276 #pragma omp teams distribute parallel for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
277 for (int k = 0; k < argc; ++k) ++k;
279 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
280 return 0;