[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_teams_distribute_simd_linear_messages.cpp
blob9a875a4d544d418b9e8f37cef470cf029e4093e2
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_default_mem_alloc;
9 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
10 extern const omp_allocator_handle_t omp_const_mem_alloc;
11 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
12 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
13 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
14 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
15 extern const omp_allocator_handle_t omp_thread_mem_alloc;
17 void xxx(int argc) {
18 int i, step_sz; // expected-note {{initialize the variable 'step_sz' to silence this warning}}
19 #pragma omp target teams distribute simd linear(i : step_sz) // expected-warning {{variable 'step_sz' is uninitialized when used here}}
20 for (i = 0; i < 10; ++i)
24 namespace X {
25 int x;
28 struct B {
29 static int ib; // expected-note {{'B::ib' declared here}}
30 static int bfoo() { return 8; }
33 int bfoo() { return 4; }
35 int z;
36 const int C1 = 1;
37 const int C2 = 2;
38 void test_linear_colons()
40 int B = 0;
42 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
43 #pragma omp target teams distribute simd linear(B:bfoo())
44 for (int i = 0; i < 10; ++i) ;
46 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
47 #pragma omp target teams distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
48 for (int i = 0; i < 10; ++i) ;
50 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
51 #pragma omp target teams distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
52 for (int i = 0; i < 10; ++i) ;
54 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
55 #pragma omp target teams distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
56 for (int i = 0; i < 10; ++i) ;
58 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
59 #pragma omp target teams distribute simd linear(B:B::bfoo())
60 for (int i = 0; i < 10; ++i) ;
62 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
63 #pragma omp target teams distribute simd linear(X::x : ::z)
64 for (int i = 0; i < 10; ++i) ;
66 // expected-error@+1 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
67 #pragma omp target teams distribute simd linear(B,::z, X::x)
68 for (int i = 0; i < 10; ++i) ;
70 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
71 #pragma omp target teams distribute simd linear(::z)
72 for (int i = 0; i < 10; ++i) ;
74 #pragma omp target teams distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}
75 for (int i = 0; i < 10; ++i) ;
77 // expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
78 #pragma omp target teams distribute simd linear(B::ib,B:C1+C2)
79 for (int i = 0; i < 10; ++i) ;
82 template<int L, class T, class N> T test_template(T* arr, N num) {
83 N i;
84 T sum = (T)0;
85 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
87 #pragma omp target teams distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
88 for (i = 0; i < num; ++i) {
89 T cur = arr[(int)ind2];
90 ind2 += L;
91 sum += cur;
93 return T();
96 template<int LEN> int test_warn() {
97 int ind2 = 0;
98 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
99 #pragma omp target teams distribute simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
100 for (int i = 0; i < 100; i++) {
101 ind2 += LEN;
103 return ind2;
106 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
107 extern S1 a;
108 class S2 {
109 mutable int a;
110 public:
111 S2():a(0) { }
113 const S2 b; // expected-note 2 {{'b' defined here}}
114 const S2 ba[5];
115 class S3 {
116 int a;
117 public:
118 S3():a(0) { }
120 const S3 ca[5];
121 class S4 {
122 int a;
123 S4();
124 public:
125 S4(int v):a(v) { }
127 class S5 {
128 int a;
129 S5():a(0) {}
130 public:
131 S5(int v):a(v) { }
134 S3 h;
135 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
137 template<class I, class C> int foomain(I argc, C **argv) {
138 I e(4);
139 I g(5);
140 int i;
141 int &j = i;
143 #pragma omp target teams distribute simd linear // expected-error {{expected '(' after 'linear'}}
144 for (int k = 0; k < argc; ++k) ++k;
146 #pragma omp target teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
147 for (int k = 0; k < argc; ++k) ++k;
149 #pragma omp target teams distribute simd linear () // expected-error {{expected expression}}
150 for (int k = 0; k < argc; ++k) ++k;
152 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
153 #pragma omp target teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
154 for (int k = 0; k < argc; ++k) ++k;
156 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
157 #pragma omp target teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
158 for (int k = 0; k < argc; ++k) ++k;
160 #pragma omp target teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
161 for (int k = 0; k < argc; ++k) ++k;
163 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
164 #pragma omp target teams distribute simd linear (argc : 5)
165 for (int k = 0; k < argc; ++k) ++k;
167 #pragma omp target teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
168 for (int k = 0; k < argc; ++k) ++k;
170 #pragma omp target teams distribute 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'}}
171 for (int k = 0; k < argc; ++k) ++k;
173 #pragma omp target teams distribute simd linear (argv[1]) // expected-error {{expected variable name}}
174 for (int k = 0; k < argc; ++k) ++k;
176 // expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
177 #pragma omp target teams distribute simd linear(e, g)
178 for (int k = 0; k < argc; ++k) ++k;
180 #pragma omp target teams distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
181 for (int k = 0; k < argc; ++k) ++k;
183 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
184 #pragma omp target teams distribute simd linear(i)
185 for (int k = 0; k < argc; ++k) ++k;
187 return 0;
190 namespace A {
191 double x;
192 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
194 namespace C {
195 using A::x;
198 int main(int argc, char **argv) {
199 double darr[100];
200 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
201 test_template<-4>(darr, 4);
202 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
203 test_warn<0>();
205 S4 e(4); // expected-note {{'e' defined here}}
206 S5 g(5); // expected-note {{'g' defined here}}
207 int i;
208 int &j = i;
210 #pragma omp target teams distribute simd linear // expected-error {{expected '(' after 'linear'}}
211 for (int k = 0; k < argc; ++k) ++k;
213 #pragma omp target teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
214 for (int k = 0; k < argc; ++k) ++k;
216 #pragma omp target teams distribute simd linear () // expected-error {{expected expression}}
217 for (int k = 0; k < argc; ++k) ++k;
219 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
220 #pragma omp target teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
221 for (int k = 0; k < argc; ++k) ++k;
223 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
224 #pragma omp target teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
225 for (int k = 0; k < argc; ++k) ++k;
227 #pragma omp target teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
228 for (int k = 0; k < argc; ++k) ++k;
230 // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
231 #pragma omp target teams distribute simd linear (argc) 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 '('}}
232 for (int k = 0; k < argc; ++k) ++k;
234 #pragma omp target teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
235 for (int k = 0; k < argc; ++k) ++k;
238 #pragma omp target teams distribute 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'}}
239 for (int k = 0; k < argc; ++k) ++k;
241 #pragma omp target teams distribute simd linear (argv[1]) // expected-error {{expected variable name}}
242 for (int k = 0; k < argc; ++k) ++k;
244 #pragma omp target teams distribute 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'}}
245 for (int k = 0; k < argc; ++k) ++k;
247 #pragma omp target teams distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
248 for (int k = 0; k < argc; ++k) ++k;
250 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
251 return 0;