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