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