blob: 11c24cbd7c7367e43141f2cfa0e655cfeecea0a6 [file] [log] [blame]
Alexey Bataeva9148882019-07-08 15:45:24 +00001// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
Kelvin Lida681182017-01-10 18:08:18 +00002
Alexey Bataeva9148882019-07-08 15:45:24 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00004
Alexey Bataev471171c2019-03-28 19:15:36 +00005typedef void **omp_allocator_handle_t;
6extern const omp_allocator_handle_t omp_default_mem_alloc;
7extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
8extern const omp_allocator_handle_t omp_const_mem_alloc;
9extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
10extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
11extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
12extern const omp_allocator_handle_t omp_pteam_mem_alloc;
13extern const omp_allocator_handle_t omp_thread_mem_alloc;
14
Alexey Bataev195ae9032019-08-08 13:42:45 +000015void xxx(int argc) {
16 int i, step; // expected-note {{initialize the variable 'step' to silence this warning}}
17#pragma omp target teams distribute simd linear(i : step) // expected-warning {{variable 'step' is uninitialized when used here}}
18 for (i = 0; i < 10; ++i)
19 ;
20}
21
Kelvin Lida681182017-01-10 18:08:18 +000022namespace X {
23 int x;
24};
25
26struct B {
27 static int ib; // expected-note {{'B::ib' declared here}}
28 static int bfoo() { return 8; }
29};
30
31int bfoo() { return 4; }
32
33int z;
34const int C1 = 1;
35const int C2 = 2;
36void test_linear_colons()
37{
38 int B = 0;
39
Alexey Bataev2b86f212017-11-29 21:31:48 +000040// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000041#pragma omp target teams distribute simd linear(B:bfoo())
42 for (int i = 0; i < 10; ++i) ;
43
Alexey Bataev2b86f212017-11-29 21:31:48 +000044// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000045#pragma omp target teams distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
46 for (int i = 0; i < 10; ++i) ;
47
Alexey Bataev2b86f212017-11-29 21:31:48 +000048// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000049#pragma omp target teams distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
50 for (int i = 0; i < 10; ++i) ;
51
Alexey Bataev2b86f212017-11-29 21:31:48 +000052// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000053#pragma omp target teams distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
54 for (int i = 0; i < 10; ++i) ;
55
Alexey Bataev2b86f212017-11-29 21:31:48 +000056// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000057#pragma omp target teams distribute simd linear(B:B::bfoo())
58 for (int i = 0; i < 10; ++i) ;
59
Alexey Bataev2b86f212017-11-29 21:31:48 +000060// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000061#pragma omp target teams distribute simd linear(X::x : ::z)
62 for (int i = 0; i < 10; ++i) ;
63
Alexey Bataev2b86f212017-11-29 21:31:48 +000064// expected-error@+1 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000065#pragma omp target teams distribute simd linear(B,::z, X::x)
66 for (int i = 0; i < 10; ++i) ;
67
Alexey Bataev2b86f212017-11-29 21:31:48 +000068// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000069#pragma omp target teams distribute simd linear(::z)
70 for (int i = 0; i < 10; ++i) ;
71
72#pragma omp target teams distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}
73 for (int i = 0; i < 10; ++i) ;
74
Alexey Bataev2b86f212017-11-29 21:31:48 +000075// expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000076#pragma omp target teams distribute simd linear(B::ib,B:C1+C2)
77 for (int i = 0; i < 10; ++i) ;
78}
79
80template<int L, class T, class N> T test_template(T* arr, N num) {
81 N i;
82 T sum = (T)0;
83 T ind2 = - num * L; // expected-note {{'ind2' defined here}}
84
85#pragma omp target teams distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
86 for (i = 0; i < num; ++i) {
87 T cur = arr[(int)ind2];
88 ind2 += L;
89 sum += cur;
90 }
91 return T();
92}
93
94template<int LEN> int test_warn() {
95 int ind2 = 0;
Alexey Bataev2b86f212017-11-29 21:31:48 +000096// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +000097 #pragma omp target teams distribute simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
98 for (int i = 0; i < 100; i++) {
99 ind2 += LEN;
100 }
101 return ind2;
102}
103
104struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
105extern S1 a;
106class S2 {
107 mutable int a;
108public:
109 S2():a(0) { }
110};
111const S2 b; // expected-note 2 {{'b' defined here}}
112const S2 ba[5];
113class S3 {
114 int a;
115public:
116 S3():a(0) { }
117};
118const S3 ca[5];
119class S4 {
120 int a;
121 S4();
122public:
123 S4(int v):a(v) { }
124};
125class S5 {
126 int a;
127 S5():a(0) {}
128public:
129 S5(int v):a(v) { }
130};
131
132S3 h;
133#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
134
135template<class I, class C> int foomain(I argc, C **argv) {
136 I e(4);
137 I g(5);
138 int i;
139 int &j = i;
140
141#pragma omp target teams distribute simd linear // expected-error {{expected '(' after 'linear'}}
142 for (int k = 0; k < argc; ++k) ++k;
143
144#pragma omp target teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
145 for (int k = 0; k < argc; ++k) ++k;
146
147#pragma omp target teams distribute simd linear () // expected-error {{expected expression}}
148 for (int k = 0; k < argc; ++k) ++k;
149
Alexey Bataev2b86f212017-11-29 21:31:48 +0000150// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000151#pragma omp target teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
152 for (int k = 0; k < argc; ++k) ++k;
153
Alexey Bataev2b86f212017-11-29 21:31:48 +0000154// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000155#pragma omp target teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
156 for (int k = 0; k < argc; ++k) ++k;
157
158#pragma omp target teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
159 for (int k = 0; k < argc; ++k) ++k;
160
Alexey Bataev2b86f212017-11-29 21:31:48 +0000161// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000162#pragma omp target teams distribute simd linear (argc : 5)
163 for (int k = 0; k < argc; ++k) ++k;
164
165#pragma omp target teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
166 for (int k = 0; k < argc; ++k) ++k;
167
Joel E. Dennybae586f2019-01-04 22:12:13 +0000168#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'}}
Kelvin Lida681182017-01-10 18:08:18 +0000169 for (int k = 0; k < argc; ++k) ++k;
170
171#pragma omp target teams distribute simd linear (argv[1]) // expected-error {{expected variable name}}
172 for (int k = 0; k < argc; ++k) ++k;
173
Alexey Bataev2b86f212017-11-29 21:31:48 +0000174// expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000175#pragma omp target teams distribute simd linear(e, g)
176 for (int k = 0; k < argc; ++k) ++k;
177
178#pragma omp target teams distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
179 for (int k = 0; k < argc; ++k) ++k;
180
Alexey Bataev2b86f212017-11-29 21:31:48 +0000181// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000182#pragma omp target teams distribute simd linear(i)
183 for (int k = 0; k < argc; ++k) ++k;
184
Kelvin Lida681182017-01-10 18:08:18 +0000185 return 0;
186}
187
188namespace A {
189double x;
190#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
191}
192namespace C {
193using A::x;
194}
195
196int main(int argc, char **argv) {
197 double darr[100];
198 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
199 test_template<-4>(darr, 4);
200 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
201 test_warn<0>();
202
203 S4 e(4); // expected-note {{'e' defined here}}
204 S5 g(5); // expected-note {{'g' defined here}}
205 int i;
206 int &j = i;
207
208#pragma omp target teams distribute simd linear // expected-error {{expected '(' after 'linear'}}
209 for (int k = 0; k < argc; ++k) ++k;
210
211#pragma omp target teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
212 for (int k = 0; k < argc; ++k) ++k;
213
214#pragma omp target teams distribute simd linear () // expected-error {{expected expression}}
215 for (int k = 0; k < argc; ++k) ++k;
216
Alexey Bataev2b86f212017-11-29 21:31:48 +0000217// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000218#pragma omp target teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
219 for (int k = 0; k < argc; ++k) ++k;
220
Alexey Bataev2b86f212017-11-29 21:31:48 +0000221// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Kelvin Lida681182017-01-10 18:08:18 +0000222#pragma omp target teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
223 for (int k = 0; k < argc; ++k) ++k;
224
225#pragma omp target teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
226 for (int k = 0; k < argc; ++k) ++k;
227
Alexey Bataev2b86f212017-11-29 21:31:48 +0000228// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
Alexey Bataeve04483e2019-03-27 14:14:31 +0000229#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 '('}}
Kelvin Lida681182017-01-10 18:08:18 +0000230 for (int k = 0; k < argc; ++k) ++k;
231
232#pragma omp target teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}
233 for (int k = 0; k < argc; ++k) ++k;
234
235
Joel E. Dennybae586f2019-01-04 22:12:13 +0000236#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'}}
Kelvin Lida681182017-01-10 18:08:18 +0000237 for (int k = 0; k < argc; ++k) ++k;
238
239#pragma omp target teams distribute simd linear (argv[1]) // expected-error {{expected variable name}}
240 for (int k = 0; k < argc; ++k) ++k;
241
242#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'}}
243 for (int k = 0; k < argc; ++k) ++k;
244
245#pragma omp target teams distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
246 for (int k = 0; k < argc; ++k) ++k;
247
Kelvin Lida681182017-01-10 18:08:18 +0000248 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
249 return 0;
250}
251