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