Clang Project

clang_source_code/test/OpenMP/target_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
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 {
16  int 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{
31  int B = 0;
32
33// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
34#pragma omp target teams distribute parallel for simd linear(B:bfoo())
35  for (int i = 0; i < 10; ++i) ;
36
37// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
38#pragma omp target teams distribute parallel for simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}
39  for (int i = 0; i < 10; ++i) ;
40
41// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
42#pragma omp target teams distribute parallel for simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
43  for (int i = 0; i < 10; ++i) ;
44
45// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
46#pragma omp target teams distribute parallel for simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}
47  for (int i = 0; i < 10; ++i) ;
48
49// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
50#pragma omp target teams distribute parallel for simd linear(B:B::bfoo())
51  for (int i = 0; i < 10; ++i) ;
52
53// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
54#pragma omp target teams distribute parallel for simd linear(X::x : ::z)
55  for (int i = 0; i < 10; ++i) ;
56
57// expected-error@+1 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
58#pragma omp target teams distribute parallel for simd linear(B,::z, X::x)
59  for (int i = 0; i < 10; ++i) ;
60
61// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
62#pragma omp target teams distribute parallel for simd linear(::z)
63  for (int i = 0; i < 10; ++i) ;
64
65#pragma omp target teams distribute parallel for simd linear(B::bfoo()) // expected-error {{expected variable name}}
66  for (int i = 0; i < 10; ++i) ;
67
68// expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
69#pragma omp target teams distribute parallel for simd linear(B::ib,B:C1+C2)
70  for (int i = 0; i < 10; ++i) ;
71}
72
73template<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 teams distribute parallel for simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}
79  for (i = 0; i < num; ++i) {
80    T cur = arr[(int)ind2];
81    ind2 += L;
82    sum += cur;
83  }
84  return T();
85}
86
87template<int LEN> int test_warn() {
88  int ind2 = 0;
89// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
90  #pragma omp target teams distribute parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}}
91  for (int i = 0; i < 100; i++) {
92    ind2 += LEN;
93  }
94  return ind2;
95}
96
97struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
98extern S1 a;
99class S2 {
100  mutable int a;
101public:
102  S2():a(0) { }
103};
104const S2 b; // expected-note 2 {{'b' defined here}}
105const S2 ba[5];
106class S3 {
107  int a;
108public:
109  S3():a(0) { }
110};
111const S3 ca[5];
112class S4 {
113  int a;
114  S4();
115public:
116  S4(int v):a(v) { }
117};
118class S5 {
119  int a;
120  S5():a(0) {}
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> int foomain(I argc, C **argv) {
129  I e(4);
130  I g(5);
131  int i;
132  int &j = i;
133
134#pragma omp target teams distribute parallel for simd linear // expected-error {{expected '(' after 'linear'}}
135  for (int k = 0; k < argc; ++k) ++k;
136
137#pragma omp target teams distribute parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
138  for (int k = 0; k < argc; ++k) ++k;
139
140#pragma omp target teams distribute parallel for simd linear () // expected-error {{expected expression}}
141  for (int k = 0; k < argc; ++k) ++k;
142
143// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
144#pragma omp target teams distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
145  for (int k = 0; k < argc; ++k) ++k;
146
147// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
148#pragma omp target teams distribute parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
149  for (int k = 0; k < argc; ++k) ++k;
150
151#pragma omp target teams distribute parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
152  for (int k = 0; k < argc; ++k) ++k;
153
154// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
155#pragma omp target teams distribute parallel for 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 '('}}
156  for (int k = 0; k < argc; ++k) ++k;
157
158#pragma omp target teams distribute parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
159  for (int k = 0; k < argc; ++k) ++k;
160
161#pragma omp target 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'}}
162  for (int k = 0; k < argc; ++k) ++k;
163
164#pragma omp target teams distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
165  for (int k = 0; k < argc; ++k) ++k;
166
167// expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
168#pragma omp target teams distribute parallel for simd linear(e, g)
169  for (int k = 0; k < argc; ++k) ++k;
170
171#pragma omp target teams distribute parallel for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
172  for (int k = 0; k < argc; ++k) ++k;
173
174// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
175#pragma omp target teams distribute parallel for simd linear(i)
176  for (int k = 0; k < argc; ++k) ++k;
177
178  return 0;
179}
180
181namespace A {
182double x;
183#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
184}
185namespace C {
186using A::x;
187}
188
189int main(int argc, char **argv) {
190  double darr[100];
191  // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
192  test_template<-4>(darr, 4);
193  // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
194  test_warn<0>();
195
196  S4 e(4); // expected-note {{'e' defined here}}
197  S5 g(5); // expected-note {{'g' defined here}}
198  int i;
199  int &j = i;
200
201#pragma omp target teams distribute parallel for simd linear // expected-error {{expected '(' after 'linear'}}
202  for (int k = 0; k < argc; ++k) ++k;
203
204#pragma omp target teams distribute parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
205  for (int k = 0; k < argc; ++k) ++k;
206
207#pragma omp target teams distribute parallel for simd linear () // expected-error {{expected expression}}
208  for (int k = 0; k < argc; ++k) ++k;
209
210// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
211#pragma omp target teams distribute parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
212  for (int k = 0; k < argc; ++k) ++k;
213
214// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
215#pragma omp target teams distribute parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
216  for (int k = 0; k < argc; ++k) ++k;
217
218#pragma omp target teams distribute parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
219  for (int k = 0; k < argc; ++k) ++k;
220
221// expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}
222#pragma omp target teams distribute parallel for simd linear (argc)
223  for (int k = 0; k < argc; ++k) ++k;
224
225#pragma omp target teams distribute parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
226  for (int k = 0; k < argc; ++k) ++k;
227
228
229#pragma omp target 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'}}
230  for (int k = 0; k < argc; ++k) ++k;
231
232#pragma omp target teams distribute parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
233  for (int k = 0; k < argc; ++k) ++k;
234
235#pragma omp target 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'}}
236  for (int k = 0; k < argc; ++k) ++k;
237
238#pragma omp target teams distribute parallel for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
239  for (int k = 0; k < argc; ++k) ++k;
240
241  foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
242  return 0;
243}
244
245