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