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