1// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
2
3void foo() {
4}
5
6bool foobool(int argc) {
7  return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13  mutable int a;
14
15public:
16  S2() : a(0) {}
17  S2(S2 &s2) : a(s2.a) {}
18  S2 &operator=(const S2 &);
19  const S2 &operator=(const S2 &) const;
20  static float S2s;
21  static const float S2sc;
22};
23const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
24const S2 b;
25const S2 ba[5];
26class S3 {
27  int a;
28  S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
29
30public:
31  S3() : a(0) {}
32  S3(S3 &s3) : a(s3.a) {}
33};
34const S3 c;         // expected-note {{global variable is predetermined as shared}}
35const S3 ca[5];     // expected-note {{global variable is predetermined as shared}}
36extern const int f; // expected-note {{global variable is predetermined as shared}}
37class S4 {
38  int a;
39  S4();             // expected-note 3 {{implicitly declared private here}}
40  S4(const S4 &s4);
41
42public:
43  S4(int v) : a(v) {}
44};
45class S5 {
46  int a;
47  S5() : a(0) {} // expected-note {{implicitly declared private here}}
48
49public:
50  S5(const S5 &s5) : a(s5.a) {}
51  S5(int v) : a(v) {}
52};
53class S6 {
54  int a;
55  S6() : a(0) {}
56
57public:
58  S6(const S6 &s6) : a(s6.a) {}
59  S6(int v) : a(v) {}
60};
61
62S3 h;
63#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
64
65template <class I, class C>
66int foomain(int argc, char **argv) {
67  I e(4);
68  I g(5);
69  int i;
70  int &j = i;                        // expected-note {{'j' defined here}}
71#pragma omp parallel for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
72  for (int k = 0; k < argc; ++k)
73    ++k;
74#pragma omp parallel for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
75  for (int k = 0; k < argc; ++k)
76    ++k;
77#pragma omp parallel for lastprivate() // expected-error {{expected expression}}
78  for (int k = 0; k < argc; ++k)
79    ++k;
80#pragma omp parallel for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
81  for (int k = 0; k < argc; ++k)
82    ++k;
83#pragma omp parallel for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
84  for (int k = 0; k < argc; ++k)
85    ++k;
86#pragma omp parallel for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
87  for (int k = 0; k < argc; ++k)
88    ++k;
89#pragma omp parallel for lastprivate(argc)
90  for (int k = 0; k < argc; ++k)
91    ++k;
92#pragma omp parallel for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
93  for (int k = 0; k < argc; ++k)
94    ++k;
95#pragma omp parallel for lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
96  for (int k = 0; k < argc; ++k)
97    ++k;
98#pragma omp parallel for lastprivate(argv[1]) // expected-error {{expected variable name}}
99  for (int k = 0; k < argc; ++k)
100    ++k;
101#pragma omp parallel for lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
102  for (int k = 0; k < argc; ++k)
103    ++k;
104#pragma omp parallel for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
105  for (int k = 0; k < argc; ++k)
106    ++k;
107#pragma omp parallel for linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel for'}}
108  for (int k = 0; k < argc; ++k)
109    ++k;
110#pragma omp parallel
111  {
112    int v = 0;
113    int i;
114#pragma omp parallel for lastprivate(i)
115    for (int k = 0; k < argc; ++k) {
116      i = k;
117      v += i;
118    }
119  }
120#pragma omp parallel shared(i)
121#pragma omp parallel private(i)
122#pragma omp parallel for lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
123  for (int k = 0; k < argc; ++k)
124    ++k;
125#pragma omp parallel for lastprivate(i)
126  for (int k = 0; k < argc; ++k)
127    ++k;
128  return 0;
129}
130
131namespace A {
132double x;
133#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
134}
135namespace B {
136using A::x;
137}
138
139int main(int argc, char **argv) {
140  const int d = 5;       // expected-note {{constant variable is predetermined as shared}}
141  const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
142  S4 e(4);
143  S5 g(5);
144  S3 m;
145  S6 n(2);
146  int i;
147  int &j = i;                        // expected-note {{'j' defined here}}
148#pragma omp parallel for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
149  for (i = 0; i < argc; ++i)
150    foo();
151#pragma omp parallel for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
152  for (i = 0; i < argc; ++i)
153    foo();
154#pragma omp parallel for lastprivate() // expected-error {{expected expression}}
155  for (i = 0; i < argc; ++i)
156    foo();
157#pragma omp parallel for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
158  for (i = 0; i < argc; ++i)
159    foo();
160#pragma omp parallel for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
161  for (i = 0; i < argc; ++i)
162    foo();
163#pragma omp parallel for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
164  for (i = 0; i < argc; ++i)
165    foo();
166#pragma omp parallel for lastprivate(argc)
167  for (i = 0; i < argc; ++i)
168    foo();
169#pragma omp parallel for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
170  for (i = 0; i < argc; ++i)
171    foo();
172#pragma omp parallel for lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be lastprivate}}
173  for (i = 0; i < argc; ++i)
174    foo();
175#pragma omp parallel for lastprivate(argv[1]) // expected-error {{expected variable name}}
176  for (i = 0; i < argc; ++i)
177    foo();
178#pragma omp parallel for lastprivate(2 * 2) // expected-error {{expected variable name}}
179  for (i = 0; i < argc; ++i)
180    foo();
181#pragma omp parallel for lastprivate(ba)
182  for (i = 0; i < argc; ++i)
183    foo();
184#pragma omp parallel for lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
185  for (i = 0; i < argc; ++i)
186    foo();
187#pragma omp parallel for lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
188  for (i = 0; i < argc; ++i)
189    foo();
190  int xa;
191#pragma omp parallel for lastprivate(xa) // OK
192  for (i = 0; i < argc; ++i)
193    foo();
194#pragma omp parallel for lastprivate(S2::S2s)
195  for (i = 0; i < argc; ++i)
196    foo();
197#pragma omp parallel for lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
198  for (i = 0; i < argc; ++i)
199    foo();
200#pragma omp parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel for'}}
201  for (i = 0; i < argc; ++i)
202    foo();
203#pragma omp parallel for lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
204  for (i = 0; i < argc; ++i)
205    foo();
206#pragma omp parallel for lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
207  for (i = 0; i < argc; ++i)
208    foo();
209#pragma omp parallel for lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
210  for (i = 0; i < argc; ++i)
211    foo();
212#pragma omp parallel for private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
213  for (i = 0; i < argc; ++i)
214    foo();
215#pragma omp parallel for lastprivate(i)
216  for (i = 0; i < argc; ++i)
217    foo();
218#pragma omp parallel private(xa)
219#pragma omp parallel for lastprivate(xa)
220  for (i = 0; i < argc; ++i)
221    foo();
222#pragma omp parallel reduction(+ : xa)
223#pragma omp parallel for lastprivate(xa)
224  for (i = 0; i < argc; ++i)
225    foo();
226#pragma omp parallel for lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
227  for (i = 0; i < argc; ++i)
228    foo();
229#pragma omp parallel for firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
230  for (i = 0; i < argc; ++i)
231    foo();
232#pragma omp parallel for lastprivate(n) firstprivate(n) // OK
233  for (i = 0; i < argc; ++i)
234    foo();
235  return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
236}
237