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 for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
72   for (int k = 0; k < argc; ++k)
73     ++k;
74 #pragma omp parallel for simd firstprivate( // 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 simd firstprivate() // expected-error {{expected expression}}
78   for (int k = 0; k < argc; ++k)
79     ++k;
80 #pragma omp parallel for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
81   for (int k = 0; k < argc; ++k)
82     ++k;
83 #pragma omp parallel for simd firstprivate(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 simd firstprivate(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 simd firstprivate(argc)
90   for (int k = 0; k < argc; ++k)
91     ++k;
92 #pragma omp parallel for simd firstprivate(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 simd firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
96   for (int k = 0; k < argc; ++k)
97     ++k;
98 #pragma omp parallel for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
99   for (int k = 0; k < argc; ++k)
100     ++k;
101 #pragma omp parallel for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
102   for (int k = 0; k < argc; ++k)
103     ++k;
104 #pragma omp parallel for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
105   for (int k = 0; k < argc; ++k)
106     ++k;
107 #pragma omp parallel for simd linear(i)
108   for (int k = 0; k < argc; ++k)
109     ++k;
110   {
111     int v = 0;
112     int i;
113 #pragma omp parallel for simd firstprivate(i)
114     for (int k = 0; k < argc; ++k) {
115       i = k;
116       v += i;
117     }
118   }
119 #pragma omp parallel shared(i)
120 #pragma omp parallel private(i)
121 #pragma omp parallel for simd firstprivate(j)
122   for (int k = 0; k < argc; ++k)
123     ++k;
124 #pragma omp parallel for simd firstprivate(i)
125   for (int k = 0; k < argc; ++k)
126     ++k;
127 #pragma omp parallel for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
128   for (i = 0; i < argc; ++i)
129     foo();
130 #pragma omp parallel private(i)
131 #pragma omp parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
132   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be firstprivate, predetermined as linear}}
133     foo();
134 #pragma omp parallel reduction(+ : i)
135 #pragma omp parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
136   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be firstprivate, predetermined as linear}}
137     foo();
138   return 0;
139 }
140 
141 namespace A {
142 double x;
143 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
144 }
145 namespace B {
146 using A::x;
147 }
148 
149 int main(int argc, char **argv) {
150   const int d = 5;
151   const int da[5] = {0};
152   S4 e(4);
153   S5 g(5);
154   S3 m;
155   S6 n(2);
156   int i;
157   int &j = i;
158 #pragma omp parallel for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
159   for (i = 0; i < argc; ++i)
160     foo();
161 #pragma omp parallel for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
162   for (i = 0; i < argc; ++i)
163     foo();
164 #pragma omp parallel for simd firstprivate() // expected-error {{expected expression}}
165   for (i = 0; i < argc; ++i)
166     foo();
167 #pragma omp parallel for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
168   for (i = 0; i < argc; ++i)
169     foo();
170 #pragma omp parallel for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
171   for (i = 0; i < argc; ++i)
172     foo();
173 #pragma omp parallel for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
174   for (i = 0; i < argc; ++i)
175     foo();
176 #pragma omp parallel for simd firstprivate(argc)
177   for (i = 0; i < argc; ++i)
178     foo();
179 #pragma omp parallel for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
180   for (i = 0; i < argc; ++i)
181     foo();
182 #pragma omp parallel for simd firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
183   for (i = 0; i < argc; ++i)
184     foo();
185 #pragma omp parallel for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
186   for (i = 0; i < argc; ++i)
187     foo();
188 #pragma omp parallel for simd firstprivate(2 * 2) // expected-error {{expected variable name}}
189   for (i = 0; i < argc; ++i)
190     foo();
191 #pragma omp parallel for simd firstprivate(ba) // OK
192   for (i = 0; i < argc; ++i)
193     foo();
194 #pragma omp parallel for simd firstprivate(ca) // OK
195   for (i = 0; i < argc; ++i)
196     foo();
197 #pragma omp parallel for simd firstprivate(da) // OK
198   for (i = 0; i < argc; ++i)
199     foo();
200   int xa;
201 #pragma omp parallel for simd firstprivate(xa) // OK
202   for (i = 0; i < argc; ++i)
203     foo();
204 #pragma omp parallel for simd firstprivate(S2::S2s) // OK
205   for (i = 0; i < argc; ++i)
206     foo();
207 #pragma omp parallel for simd firstprivate(S2::S2sc) // OK
208   for (i = 0; i < argc; ++i)
209     foo();
210 #pragma omp parallel for simd safelen(5)
211   for (i = 0; i < argc; ++i)
212     foo();
213 #pragma omp parallel for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
214   for (i = 0; i < argc; ++i)
215     foo();
216 #pragma omp parallel for simd firstprivate(m) // OK
217   for (i = 0; i < argc; ++i)
218     foo();
219 #pragma omp parallel for simd firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
220   for (i = 0; i < argc; ++i)
221     foo();
222 #pragma omp parallel for simd private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
223   for (i = 0; i < argc; ++i)
224     foo();
225 #pragma omp parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
226   for (i = 0; i < argc; ++i)    // expected-error {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be firstprivate, predetermined as linear}}
227     foo();
228 #pragma omp parallel for simd firstprivate(xa) // OK: may be firstprivate
229   for (i = 0; i < argc; ++i)
230     foo();
231 #pragma omp parallel for simd firstprivate(j)
232   for (i = 0; i < argc; ++i)
233     foo();
234 #pragma omp parallel for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
235   for (i = 0; i < argc; ++i)
236     foo();
237 #pragma omp parallel for simd lastprivate(n) firstprivate(n) // OK
238   for (i = 0; i < argc; ++i)
239     foo();
240 #pragma omp parallel
241   {
242     int v = 0;
243     int i;
244 #pragma omp parallel for simd firstprivate(i)
245     for (int k = 0; k < argc; ++k) {
246       i = k;
247       v += i;
248     }
249   }
250 #pragma omp parallel private(i)
251 #pragma omp parallel for simd firstprivate(i) // expected-note {{defined as firstprivate}}
252   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be firstprivate, predetermined as linear}}
253     foo();
254 #pragma omp parallel reduction(+ : i)
255 #pragma omp parallel for simd firstprivate(i)  // expected-note {{defined as firstprivate}}
256   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be firstprivate, predetermined as linear}}
257     foo();
258   static int si;
259 #pragma omp parallel for simd firstprivate(si) // OK
260   for (i = 0; i < argc; ++i)
261     si = i + 2;
262 
263   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
264 }
265