Clang Project

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