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