1 // RUN: %clang_cc1 -verify -fopenmp %s
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s
4 
5 void foo() {
6 }
7 
8 bool foobool(int argc) {
9   return argc;
10 }
11 
12 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13 extern S1 a;
14 class S2 {
15   mutable int a;
16 
17 public:
18   S2() : a(0) {}
19   S2(const S2 &s2) : a(s2.a) {}
20   static float S2s;
21   static const float S2sc;
22 };
23 const float S2::S2sc = 0;
24 const S2 b;
25 const S2 ba[5];
26 class S3 {
27   int a;
28   S3 &operator=(const S3 &s3);
29 
30 public:
31   S3() : a(0) {}
32   S3(const S3 &s3) : a(s3.a) {}
33 };
34 const S3 c;
35 const S3 ca[5];
36 extern const int f;
37 class S4 {
38   int a;
39   S4();
40   S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
41 
42 public:
43   S4(int v) : a(v) {}
44 };
45 class S5 {
46   int a;
47   S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
48 
49 public:
50   S5() : a(0) {}
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   C g(5);
69   int i;
70   int &j = i;
71 #pragma omp parallel
72 #pragma omp for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
73   for (int k = 0; k < argc; ++k)
74     ++k;
75 #pragma omp parallel
76 #pragma omp for simd firstprivate( // 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 simd firstprivate() // expected-error {{expected expression}}
81   for (int k = 0; k < argc; ++k)
82     ++k;
83 #pragma omp parallel
84 #pragma omp for simd firstprivate(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 simd firstprivate(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 simd firstprivate(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 simd firstprivate(argc)
97   for (int k = 0; k < argc; ++k)
98     ++k;
99 #pragma omp parallel
100 #pragma omp for simd firstprivate(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 simd firstprivate(a, b) // expected-error {{a firstprivate variable with incomplete type 'S1'}}
105   for (int k = 0; k < argc; ++k)
106     ++k;
107 #pragma omp parallel
108 #pragma omp for simd firstprivate(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 simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
113   for (int k = 0; k < argc; ++k)
114     ++k;
115 #pragma omp parallel
116 #pragma omp for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
117   for (int k = 0; k < argc; ++k)
118     ++k;
119 #pragma omp parallel
120 #pragma omp for simd linear(i)
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 simd' directive into a parallel or another task region?}}
127 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate 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 simd firstprivate(j)
136   for (int k = 0; k < argc; ++k)
137     ++k;
138 #pragma omp parallel
139 #pragma omp for simd firstprivate(i)
140   for (int k = 0; k < argc; ++k)
141     ++k;
142 #pragma omp parallel
143 #pragma omp for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
144   for (i = 0; i < argc; ++i)
145     foo();
146 #pragma omp parallel private(i) // expected-note {{defined as private}}
147 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
148   for (i = 0; i < argc; ++i)
149     foo();
150 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
151 #pragma omp for simd firstprivate(i)       // expected-error {{firstprivate variable must be shared}}
152   for (int k = 0; k < argc; ++k)
153     foo();
154   return 0;
155 }
156 
157 namespace A {
158 double x;
159 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
160 }
161 namespace B {
162 using A::x;
163 }
164 
165 int main(int argc, char **argv) {
166   const int d = 5;
167   const int da[5] = {0};
168   S4 e(4);
169   S5 g(5);
170   S3 m;
171   S6 n(2);
172   int i;
173   int &j = i;
174 #pragma omp parallel
175 #pragma omp for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
176   for (i = 0; i < argc; ++i)
177     foo();
178 #pragma omp parallel
179 #pragma omp for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
180   for (i = 0; i < argc; ++i)
181     foo();
182 #pragma omp parallel
183 #pragma omp for simd firstprivate() // expected-error {{expected expression}}
184   for (i = 0; i < argc; ++i)
185     foo();
186 #pragma omp parallel
187 #pragma omp for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
188   for (i = 0; i < argc; ++i)
189     foo();
190 #pragma omp parallel
191 #pragma omp for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
192   for (i = 0; i < argc; ++i)
193     foo();
194 #pragma omp parallel
195 #pragma omp for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
196   for (i = 0; i < argc; ++i)
197     foo();
198 #pragma omp parallel
199 #pragma omp for simd firstprivate(argc)
200   for (i = 0; i < argc; ++i)
201     foo();
202 #pragma omp parallel
203 #pragma omp for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
204   for (i = 0; i < argc; ++i)
205     foo();
206 #pragma omp parallel
207 #pragma omp for simd firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
208   for (i = 0; i < argc; ++i)
209     foo();
210 #pragma omp parallel
211 #pragma omp for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
212   for (i = 0; i < argc; ++i)
213     foo();
214 #pragma omp parallel
215 #pragma omp for simd firstprivate(2 * 2) // expected-error {{expected variable name}}
216   for (i = 0; i < argc; ++i)
217     foo();
218 #pragma omp parallel
219 #pragma omp for simd firstprivate(ba) // OK
220   for (i = 0; i < argc; ++i)
221     foo();
222 #pragma omp parallel
223 #pragma omp for simd firstprivate(ca) // OK
224   for (i = 0; i < argc; ++i)
225     foo();
226 #pragma omp parallel
227 #pragma omp for simd firstprivate(da) // OK
228   for (i = 0; i < argc; ++i)
229     foo();
230   int xa;
231 #pragma omp parallel
232 #pragma omp for simd firstprivate(xa) // OK
233   for (i = 0; i < argc; ++i)
234     foo();
235 #pragma omp parallel
236 #pragma omp for simd firstprivate(S2::S2s) // OK
237   for (i = 0; i < argc; ++i)
238     foo();
239 #pragma omp parallel
240 #pragma omp for simd firstprivate(S2::S2sc) // OK
241   for (i = 0; i < argc; ++i)
242     foo();
243 #pragma omp parallel
244 #pragma omp for simd safelen(5)
245   for (i = 0; i < argc; ++i)
246     foo();
247 #pragma omp parallel
248 #pragma omp for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
249   for (i = 0; i < argc; ++i)
250     foo();
251 #pragma omp parallel
252 #pragma omp for simd firstprivate(m) // OK
253   for (i = 0; i < argc; ++i)
254     foo();
255 #pragma omp parallel
256 #pragma omp for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
257   for (i = 0; i < argc; ++i)
258     foo();
259 #pragma omp parallel
260 #pragma omp for simd firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
261   for (i = 0; i < argc; ++i)
262     foo();
263 #pragma omp parallel
264 #pragma omp for simd private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
265   for (i = 0; i < argc; ++i)
266     foo();
267 #pragma omp parallel
268 #pragma omp for simd firstprivate(i) // expected-note {{defined as firstprivate}}
269   for (i = 0; i < argc; ++i)    // expected-error {{loop iteration variable in the associated loop of 'omp for simd' directive may not be firstprivate, predetermined as linear}}
270     foo();
271 #pragma omp parallel shared(xa)
272 #pragma omp for simd firstprivate(xa) // OK: may be firstprivate
273   for (i = 0; i < argc; ++i)
274     foo();
275 #pragma omp parallel
276 #pragma omp for simd firstprivate(j)
277   for (i = 0; i < argc; ++i)
278     foo();
279 #pragma omp parallel
280 #pragma omp for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
281   for (i = 0; i < argc; ++i)
282     foo();
283 #pragma omp parallel
284 #pragma omp for simd lastprivate(n) firstprivate(n) // OK
285   for (i = 0; i < argc; ++i)
286     foo();
287 #pragma omp parallel
288   {
289     int v = 0;
290     int i;                      // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for simd' directive into a parallel or another task region?}}
291 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
292     for (int k = 0; k < argc; ++k) {
293       i = k;
294       v += i;
295     }
296   }
297 #pragma omp parallel private(i) // expected-note {{defined as private}}
298 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
299   for (i = 0; i < argc; ++i)
300     foo();
301 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
302 #pragma omp for simd firstprivate(i)       // expected-error {{firstprivate variable must be shared}}
303   for (i = 0; i < argc; ++i)
304     foo();
305   static int si;
306 #pragma omp for simd firstprivate(si)
307   for (i = 0; i < argc; ++i)
308     si = i + 1;
309 
310   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
311 }
312