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