1*73e5d7bdSFazlay Rabbi // RUN: %clang_cc1 -x c++ -std=c++11 -verify -fopenmp %s -Wuninitialized
2*73e5d7bdSFazlay Rabbi 
3*73e5d7bdSFazlay Rabbi // RUN: %clang_cc1 -x c++ -std=c++11 -verify -fopenmp-simd %s -Wuninitialized
4*73e5d7bdSFazlay Rabbi 
5*73e5d7bdSFazlay Rabbi struct B {
6*73e5d7bdSFazlay Rabbi   static int ib[20]; // expected-note 0 {{'B::ib' declared here}}
bfooB7*73e5d7bdSFazlay Rabbi   static constexpr int bfoo() { return 8; }
8*73e5d7bdSFazlay Rabbi };
9*73e5d7bdSFazlay Rabbi namespace X {
10*73e5d7bdSFazlay Rabbi   B x; // expected-note {{'x' defined here}}
11*73e5d7bdSFazlay Rabbi };
bfoo()12*73e5d7bdSFazlay Rabbi constexpr int bfoo() { return 4; }
13*73e5d7bdSFazlay Rabbi 
14*73e5d7bdSFazlay Rabbi int **z;
15*73e5d7bdSFazlay Rabbi const int C1 = 1;
16*73e5d7bdSFazlay Rabbi const int C2 = 2;
test_aligned_colons(int * & rp)17*73e5d7bdSFazlay Rabbi void test_aligned_colons(int *&rp)
18*73e5d7bdSFazlay Rabbi {
19*73e5d7bdSFazlay Rabbi   int *B = 0;
20*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B:bfoo())
21*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
22*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
23*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B::ib:B:bfoo())
24*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
25*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B:B::bfoo())
26*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
27*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
28*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(z:B:bfoo())
29*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
30*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B:B::bfoo())
31*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
32*73e5d7bdSFazlay Rabbi   // expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'int **'}}
33*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'B'}}
34*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(X::x : ::z)
35*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
36*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'B'}}
37*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B,rp,::z: X::x)
38*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
39*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(::z)
40*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
41*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{expected variable name}}
42*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B::bfoo())
43*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
44*73e5d7bdSFazlay Rabbi   // expected-warning@+1 {{aligned clause will be ignored because the requested alignment is not a power of 2}}
45*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(B::ib,B:C1+C2)
46*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 10; ++i) ;
47*73e5d7bdSFazlay Rabbi }
48*73e5d7bdSFazlay Rabbi 
49*73e5d7bdSFazlay Rabbi // expected-note@+1 {{'num' defined here}}
test_template(T * arr,N num)50*73e5d7bdSFazlay Rabbi template<int L, class T, class N> T test_template(T* arr, N num) {
51*73e5d7bdSFazlay Rabbi   N i;
52*73e5d7bdSFazlay Rabbi   T sum = (T)0;
53*73e5d7bdSFazlay Rabbi   T ind2 = - num * L;
54*73e5d7bdSFazlay Rabbi   // Negative number is passed as L.
55*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument to 'aligned' clause must be a strictly positive integer value}}
56*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(arr:L)
57*73e5d7bdSFazlay Rabbi   for (i = 0; i < num; ++i) {
58*73e5d7bdSFazlay Rabbi     T cur = arr[(int)ind2];
59*73e5d7bdSFazlay Rabbi     ind2 += L;
60*73e5d7bdSFazlay Rabbi     sum += cur;
61*73e5d7bdSFazlay Rabbi   }
62*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
63*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(num:4)
64*73e5d7bdSFazlay Rabbi   for (i = 0; i < num; ++i);
65*73e5d7bdSFazlay Rabbi   return T();
66*73e5d7bdSFazlay Rabbi }
67*73e5d7bdSFazlay Rabbi 
test_warn()68*73e5d7bdSFazlay Rabbi template<int LEN> int test_warn() {
69*73e5d7bdSFazlay Rabbi   int *ind2 = 0;
70*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument to 'aligned' clause must be a strictly positive integer value}}
71*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(ind2:LEN)
72*73e5d7bdSFazlay Rabbi   for (int i = 0; i < 100; i++) {
73*73e5d7bdSFazlay Rabbi     ind2 += LEN;
74*73e5d7bdSFazlay Rabbi   }
75*73e5d7bdSFazlay Rabbi   return 0;
76*73e5d7bdSFazlay Rabbi }
77*73e5d7bdSFazlay Rabbi 
78*73e5d7bdSFazlay Rabbi struct S1; // expected-note 2 {{declared here}}
79*73e5d7bdSFazlay Rabbi extern S1 a; // expected-note {{'a' declared here}}
80*73e5d7bdSFazlay Rabbi class S2 {
81*73e5d7bdSFazlay Rabbi   mutable int a;
82*73e5d7bdSFazlay Rabbi public:
S2()83*73e5d7bdSFazlay Rabbi   S2():a(0) { }
84*73e5d7bdSFazlay Rabbi };
85*73e5d7bdSFazlay Rabbi const S2 b; // expected-note 1 {{'b' defined here}}
86*73e5d7bdSFazlay Rabbi const S2 ba[5];
87*73e5d7bdSFazlay Rabbi class S3 {
88*73e5d7bdSFazlay Rabbi   int a;
89*73e5d7bdSFazlay Rabbi public:
S3()90*73e5d7bdSFazlay Rabbi   S3():a(0) { }
91*73e5d7bdSFazlay Rabbi };
92*73e5d7bdSFazlay Rabbi const S3 ca[5];
93*73e5d7bdSFazlay Rabbi class S4 {
94*73e5d7bdSFazlay Rabbi   int a;
95*73e5d7bdSFazlay Rabbi   S4();
96*73e5d7bdSFazlay Rabbi public:
S4(int v)97*73e5d7bdSFazlay Rabbi   S4(int v):a(v) { }
98*73e5d7bdSFazlay Rabbi };
99*73e5d7bdSFazlay Rabbi class S5 {
100*73e5d7bdSFazlay Rabbi   int a;
S5()101*73e5d7bdSFazlay Rabbi   S5():a(0) {}
102*73e5d7bdSFazlay Rabbi public:
S5(int v)103*73e5d7bdSFazlay Rabbi   S5(int v):a(v) { }
104*73e5d7bdSFazlay Rabbi };
105*73e5d7bdSFazlay Rabbi 
106*73e5d7bdSFazlay Rabbi S3 h; // expected-note 2 {{'h' defined here}}
107*73e5d7bdSFazlay Rabbi #pragma omp threadprivate(h)
108*73e5d7bdSFazlay Rabbi 
foomain(I argc,C ** argv)109*73e5d7bdSFazlay Rabbi template<class I, class C> int foomain(I argc, C **argv) {
110*73e5d7bdSFazlay Rabbi   I e(argc);
111*73e5d7bdSFazlay Rabbi   I g(argc);
112*73e5d7bdSFazlay Rabbi   int i; // expected-note {{'i' defined here}}
113*73e5d7bdSFazlay Rabbi   // expected-note@+1 {{declared here}}
114*73e5d7bdSFazlay Rabbi   int &j = i;
115*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned // expected-error {{expected '(' after 'aligned'}}
116*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
117*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
118*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
119*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned () // expected-error {{expected expression}}
120*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
121*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
122*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
123*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
124*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
125*73e5d7bdSFazlay Rabbi // FIXME: Should argc really be a pointer?
126*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (*argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
127*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
128*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argc : 5) // expected-warning {{aligned clause will be ignored because the requested alignment is not a power of 2}}
129*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
130*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (S1) // expected-error {{'S1' does not refer to a value}}
131*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
132*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argv[1]) // expected-error {{expected variable name}}
133*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
134*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(e, g)
135*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
136*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S3'}}
137*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(h)
138*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
139*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
140*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(i)
141*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
142*73e5d7bdSFazlay Rabbi   #pragma omp parallel
143*73e5d7bdSFazlay Rabbi   {
144*73e5d7bdSFazlay Rabbi     int *v = 0;
145*73e5d7bdSFazlay Rabbi     I i;
146*73e5d7bdSFazlay Rabbi     #pragma omp masked taskloop simd aligned(v:16)
147*73e5d7bdSFazlay Rabbi     for (I k = 0; k < argc; ++k) { i = k; v += 2; }
148*73e5d7bdSFazlay Rabbi   }
149*73e5d7bdSFazlay Rabbi   float *f;
150*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(f)
151*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
152*73e5d7bdSFazlay Rabbi   int v = 0;
153*73e5d7bdSFazlay Rabbi   // expected-note@+2 {{initializer of 'j' is not a constant expression}}
154*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{integral constant expression}}
155*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(f:j)
156*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) { ++k; v += j; }
157*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(f)
158*73e5d7bdSFazlay Rabbi   for (I k = 0; k < argc; ++k) ++k;
159*73e5d7bdSFazlay Rabbi   return 0;
160*73e5d7bdSFazlay Rabbi }
161*73e5d7bdSFazlay Rabbi 
162*73e5d7bdSFazlay Rabbi // expected-note@+1 2 {{'argc' defined here}}
main(int argc,char ** argv)163*73e5d7bdSFazlay Rabbi int main(int argc, char **argv) {
164*73e5d7bdSFazlay Rabbi   double darr[100];
165*73e5d7bdSFazlay Rabbi   // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
166*73e5d7bdSFazlay Rabbi   test_template<-4>(darr, 4);
167*73e5d7bdSFazlay Rabbi   test_warn<4>(); // ok
168*73e5d7bdSFazlay Rabbi   // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
169*73e5d7bdSFazlay Rabbi   test_warn<0>();
170*73e5d7bdSFazlay Rabbi 
171*73e5d7bdSFazlay Rabbi   int i;
172*73e5d7bdSFazlay Rabbi   int &j = i;
173*73e5d7bdSFazlay Rabbi   int tid = 0;
174*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned filter(tid) // expected-error {{expected '(' after 'aligned'}}
175*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
176*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
177*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
178*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned () // expected-error {{expected expression}}
179*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
180*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argv // expected-error {{expected ')'}} expected-note {{to match this '('}}
181*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
182*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
183*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
184*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
185*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
186*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
187*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
188*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argc)
189*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
190*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (S1) // expected-error {{'S1' does not refer to a value}}
191*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
192*73e5d7bdSFazlay Rabbi   // expected-error@+2 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S1'}}
193*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S2'}}
194*73e5d7bdSFazlay Rabbi #pragma omp masked taskloop simd aligned(a, b)
195*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
196*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned (argv[1]) // expected-error {{expected variable name}}
197*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
198*73e5d7bdSFazlay Rabbi   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S3'}}
199*73e5d7bdSFazlay Rabbi   #pragma omp masked taskloop simd aligned(h)
200*73e5d7bdSFazlay Rabbi   for (int k = 0; k < argc; ++k) ++k;
201*73e5d7bdSFazlay Rabbi   int *pargc = &argc;
202*73e5d7bdSFazlay Rabbi   // expected-note@+1 {{in instantiation of function template specialization 'foomain<int *, char>' requested here}}
203*73e5d7bdSFazlay Rabbi   foomain<int*,char>(pargc,argv);
204*73e5d7bdSFazlay Rabbi   return 0;
205*73e5d7bdSFazlay Rabbi }
206*73e5d7bdSFazlay Rabbi 
207