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