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(S2 & s2)17   S2(S2 &s2) : a(s2.a) {}
18   static float S2s; // expected-note {{static data member is predetermined as shared}}
19   static const float S2sc;
20 };
21 const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
22 const S2 b;
23 const S2 ba[5];
24 class S3 { // expected-note 2 {{'S3' declared here}}
25   int a;
26   S3 &operator=(const S3 &s3);
27 
28 public:
S3()29   S3() : a(0) {}
S3(S3 & s3)30   S3(S3 &s3) : a(s3.a) {}
31 };
32 const S3 c;         // expected-note {{global variable is predetermined as shared}}
33 const S3 ca[5];     // expected-note {{global variable is predetermined as shared}}
34 extern const int f; // expected-note {{global variable is predetermined as shared}}
35 class S4 {          // expected-note 3 {{'S4' declared here}}
36   int a;
37   S4();
38   S4(const S4 &s4);
39 
40 public:
S4(int v)41   S4(int v) : a(v) {}
42 };
43 class S5 { // expected-note {{'S5' declared here}}
44   int a;
S5()45   S5() : a(0) {}
46 
47 public:
S5(const S5 & s5)48   S5(const S5 &s5) : a(s5.a) {}
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); // expected-note {{'e' defined here}}
66   I g(5); // expected-note {{'g' defined here}}
67   int i;
68   int &j = i; // expected-note {{'j' defined here}}
69 #pragma omp parallel
70 #pragma omp for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
71   for (int k = 0; k < argc; ++k)
72     ++k;
73 #pragma omp parallel
74 #pragma omp 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
78 #pragma omp for lastprivate() // expected-error {{expected expression}}
79   for (int k = 0; k < argc; ++k)
80     ++k;
81 #pragma omp parallel
82 #pragma omp for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
83   for (int k = 0; k < argc; ++k)
84     ++k;
85 #pragma omp parallel
86 #pragma omp for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
87   for (int k = 0; k < argc; ++k)
88     ++k;
89 #pragma omp parallel
90 #pragma omp for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
91   for (int k = 0; k < argc; ++k)
92     ++k;
93 #pragma omp parallel
94 #pragma omp for lastprivate(argc)
95   for (int k = 0; k < argc; ++k)
96     ++k;
97 #pragma omp parallel
98 #pragma omp for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
99   for (int k = 0; k < argc; ++k)
100     ++k;
101 #pragma omp parallel
102 #pragma omp for lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
103   for (int k = 0; k < argc; ++k)
104     ++k;
105 #pragma omp parallel
106 #pragma omp for lastprivate(argv[1]) // expected-error {{expected variable name}}
107   for (int k = 0; k < argc; ++k)
108     ++k;
109 #pragma omp parallel
110 #pragma omp for lastprivate(e, g) // expected-error 2 {{lastprivate variable must have an accessible, unambiguous default constructor}}
111   for (int k = 0; k < argc; ++k)
112     ++k;
113 #pragma omp parallel
114 #pragma omp for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
115   for (int k = 0; k < argc; ++k)
116     ++k;
117 #pragma omp parallel
118 #pragma omp for linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp for'}}
119   for (int k = 0; k < argc; ++k)
120     ++k;
121 #pragma omp parallel
122   {
123     int v = 0;
124     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?}}
125 #pragma omp for lastprivate(i) // expected-error {{lastprivate variable must be shared}}
126     for (int k = 0; k < argc; ++k) {
127       i = k;
128       v += i;
129     }
130   }
131 #pragma omp parallel shared(i)
132 #pragma omp parallel private(i)
133 #pragma omp for lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
134   for (int k = 0; k < argc; ++k)
135     ++k;
136 #pragma omp parallel
137 #pragma omp for lastprivate(i)
138   for (int k = 0; k < argc; ++k)
139     ++k;
140   return 0;
141 }
142 
main(int argc,char ** argv)143 int main(int argc, char **argv) {
144   const int d = 5;       // expected-note {{constant variable is predetermined as shared}}
145   const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
146   S4 e(4);               // expected-note {{'e' defined here}}
147   S5 g(5);               // expected-note {{'g' defined here}}
148   S3 m;                  // expected-note 2 {{'m' defined here}}
149   S6 n(2);
150   int i;
151   int &j = i; // expected-note {{'j' defined here}}
152 #pragma omp parallel
153 #pragma omp for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
154   for (i = 0; i < argc; ++i)
155     foo();
156 #pragma omp parallel
157 #pragma omp for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
158   for (i = 0; i < argc; ++i)
159     foo();
160 #pragma omp parallel
161 #pragma omp for lastprivate() // expected-error {{expected expression}}
162   for (i = 0; i < argc; ++i)
163     foo();
164 #pragma omp parallel
165 #pragma omp for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
166   for (i = 0; i < argc; ++i)
167     foo();
168 #pragma omp parallel
169 #pragma omp for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
170   for (i = 0; i < argc; ++i)
171     foo();
172 #pragma omp parallel
173 #pragma omp for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
174   for (i = 0; i < argc; ++i)
175     foo();
176 #pragma omp parallel
177 #pragma omp for lastprivate(argc)
178   for (i = 0; i < argc; ++i)
179     foo();
180 #pragma omp parallel
181 #pragma omp for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
182   for (i = 0; i < argc; ++i)
183     foo();
184 #pragma omp parallel
185 #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}}
186   for (i = 0; i < argc; ++i)
187     foo();
188 #pragma omp parallel
189 #pragma omp for lastprivate(argv[1]) // expected-error {{expected variable name}}
190   for (i = 0; i < argc; ++i)
191     foo();
192 #pragma omp parallel
193 #pragma omp for lastprivate(2 * 2) // expected-error {{expected variable name}}
194   for (i = 0; i < argc; ++i)
195     foo();
196 #pragma omp parallel
197 #pragma omp for lastprivate(ba)
198   for (i = 0; i < argc; ++i)
199     foo();
200 #pragma omp parallel
201 #pragma omp for lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
202   for (i = 0; i < argc; ++i)
203     foo();
204 #pragma omp parallel
205 #pragma omp for lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
206   for (i = 0; i < argc; ++i)
207     foo();
208   int xa;
209 #pragma omp parallel
210 #pragma omp for lastprivate(xa) // OK
211   for (i = 0; i < argc; ++i)
212     foo();
213 #pragma omp parallel
214 #pragma omp for lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
215   for (i = 0; i < argc; ++i)
216     foo();
217 #pragma omp parallel
218 #pragma omp for lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
219   for (i = 0; i < argc; ++i)
220     foo();
221 #pragma omp parallel
222 #pragma omp for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp for'}}
223   for (i = 0; i < argc; ++i)
224     foo();
225 #pragma omp parallel
226 #pragma omp for lastprivate(e, g) // expected-error 2 {{lastprivate variable must have an accessible, unambiguous default constructor}}
227   for (i = 0; i < argc; ++i)
228     foo();
229 #pragma omp parallel
230 #pragma omp for lastprivate(m) // expected-error {{lastprivate variable must have an accessible, unambiguous copy assignment operator}}
231   for (i = 0; i < argc; ++i)
232     foo();
233 #pragma omp parallel
234 #pragma omp for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
235   for (i = 0; i < argc; ++i)
236     foo();
237 #pragma omp parallel
238 #pragma omp for private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
239   for (i = 0; i < argc; ++i)
240     foo();
241 #pragma omp parallel
242 #pragma omp for lastprivate(i)
243   for (i = 0; i < argc; ++i)
244     foo();
245 #pragma omp parallel private(xa) // expected-note {{defined as private}}
246 #pragma omp for lastprivate(xa)  // expected-error {{lastprivate variable must be shared}}
247   for (i = 0; i < argc; ++i)
248     foo();
249 #pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
250 #pragma omp for lastprivate(xa)        // expected-error {{lastprivate variable must be shared}}
251   for (i = 0; i < argc; ++i)
252     foo();
253 #pragma omp parallel
254 #pragma omp for lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
255   for (i = 0; i < argc; ++i)
256     foo();
257 #pragma omp parallel
258 #pragma omp for firstprivate(m) lastprivate(m) // expected-error {{lastprivate variable must have an accessible, unambiguous copy assignment operator}}
259   for (i = 0; i < argc; ++i)
260     foo();
261 #pragma omp parallel
262 #pragma omp for lastprivate(n) firstprivate(n) // OK
263   for (i = 0; i < argc; ++i)
264     foo();
265   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
266 }
267