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