Clang Project

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