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 
13 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14 extern S1 a;
15 class S2 {
16   mutable int a;
17 
18 public:
S2()19   S2() : a(0) {}
20 };
21 const S2 b;
22 const S2 ba[5];
23 class S3 {
24   int a;
25 
26 public:
S3()27   S3() : a(0) {}
28 };
29 const S3 ca[5];
30 class S4 {
31   int a;
32   S4(); // expected-note {{implicitly declared private here}}
33 
34 public:
S4(int v)35   S4(int v) : a(v) {
36 #pragma omp for simd private(a) private(this->a)
37     for (int k = 0; k < v; ++k)
38       ++this->a;
39   }
40 };
41 class S5 {
42   int a;
S5()43   S5() : a(0) {} // expected-note {{implicitly declared private here}}
44 
45 public:
S5(int v)46   S5(int v) : a(v) {}
operator =(S5 & s)47   S5 &operator=(S5 &s) {
48 #pragma omp for simd private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
49     for (int k = 0; k < s.a; ++k)
50       ++s.a;
51     return *this;
52   }
53 };
54 
55 template <typename T>
56 class S6 {
57 public:
58   T a;
59 
S6()60   S6() : a(0) {}
S6(T v)61   S6(T v) : a(v) {
62 #pragma omp for simd private(a) private(this->a)
63     for (int k = 0; k < v; ++k)
64       ++this->a;
65   }
operator =(S6 & s)66   S6 &operator=(S6 &s) {
67 #pragma omp for simd private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
68     for (int k = 0; k < s.a; ++k)
69       ++s.a;
70     return *this;
71   }
72 };
73 
74 template <typename T>
75 class S7 : public T {
76   T a;
S7()77   S7() : a(0) {}
78 
79 public:
S7(T v)80   S7(T v) : a(v) {
81 #pragma omp for simd private(a) private(this->a) private(T::a)
82     for (int k = 0; k < a.a; ++k)
83       ++this->a.a;
84   }
operator =(S7 & s)85   S7 &operator=(S7 &s) {
86 #pragma omp for simd private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
87     for (int k = 0; k < s.a.a; ++k)
88       ++s.a.a;
89     return *this;
90   }
91 };
92 
93 S3 h;
94 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
95 
96 template <class I, class C>
foomain(I argc,C ** argv)97 int foomain(I argc, C **argv) {
98   I e(4);
99   I g(5);
100   int i;
101   int &j = i;
102 #pragma omp for simd private // expected-error {{expected '(' after 'private'}}
103   for (int k = 0; k < argc; ++k)
104     ++k;
105 #pragma omp for simd private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
106   for (int k = 0; k < argc; ++k)
107     ++k;
108 #pragma omp for simd private() // expected-error {{expected expression}}
109   for (int k = 0; k < argc; ++k)
110     ++k;
111 #pragma omp for simd private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
112   for (int k = 0; k < argc; ++k)
113     ++k;
114 #pragma omp for simd private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
115   for (int k = 0; k < argc; ++k)
116     ++k;
117 #pragma omp for simd private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
118   for (int k = 0; k < argc; ++k)
119     ++k;
120 #pragma omp for simd private(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 '('}}
121   for (int k = 0; k < argc; ++k)
122     ++k;
123 #pragma omp for simd private(S1) // expected-error {{'S1' does not refer to a value}}
124   for (int k = 0; k < argc; ++k)
125     ++k;
126 #pragma omp for simd private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
127   for (int k = 0; k < argc; ++k)
128     ++k;
129 #pragma omp for simd private(argv[1]) // expected-error {{expected variable name}}
130   for (int k = 0; k < argc; ++k)
131     ++k;
132 #pragma omp for simd private(e, g)
133   for (int k = 0; k < argc; ++k)
134     ++k;
135 #pragma omp for simd private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
136   for (int k = 0; k < argc; ++k)
137     ++k;
138 #pragma omp for simd shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp for simd'}}
139   for (int k = 0; k < argc; ++k)
140     ++k;
141 #pragma omp parallel
142   {
143     int v = 0;
144     int i;
145 #pragma omp for simd private(i)
146     for (int k = 0; k < argc; ++k) {
147       i = k;
148       v += i;
149     }
150   }
151 #pragma omp parallel shared(i)
152 #pragma omp parallel private(i)
153 #pragma omp for simd private(j)
154   for (int k = 0; k < argc; ++k)
155     ++k;
156 #pragma omp for simd private(i)
157   for (int k = 0; k < argc; ++k)
158     ++k;
159   return 0;
160 }
161 
162 namespace A {
163 double x;
164 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
165 }
166 namespace B {
167 using A::x;
168 }
169 
main(int argc,char ** argv)170 int main(int argc, char **argv) {
171   S4 e(4);
172   S5 g(5);
173   S6<float> s6(0.0) , s6_0(1.0);
174   S7<S6<float> > s7(0.0) , s7_0(1.0);
175   int i;
176   int &j = i;
177 #pragma omp for simd private // expected-error {{expected '(' after 'private'}}
178   for (int k = 0; k < argc; ++k)
179     ++k;
180 #pragma omp for simd private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181   for (int k = 0; k < argc; ++k)
182     ++k;
183 #pragma omp for simd private() // expected-error {{expected expression}}
184   for (int k = 0; k < argc; ++k)
185     ++k;
186 #pragma omp for simd private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
187   for (int k = 0; k < argc; ++k)
188     ++k;
189 #pragma omp for simd private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
190   for (int k = 0; k < argc; ++k)
191     ++k;
192 #pragma omp for simd private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
193   for (int k = 0; k < argc; ++k)
194     ++k;
195 #pragma omp for simd private(argc)
196   for (int k = 0; k < argc; ++k)
197     ++k;
198 #pragma omp for simd private(S1) // expected-error {{'S1' does not refer to a value}}
199   for (int k = 0; k < argc; ++k)
200     ++k;
201 #pragma omp for simd private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
202   for (int k = 0; k < argc; ++k)
203     ++k;
204 #pragma omp for simd private(argv[1]) // expected-error {{expected variable name}}
205   for (int k = 0; k < argc; ++k)
206     ++k;
207 #pragma omp for simd private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
208   for (int k = 0; k < argc; ++k)
209     ++k;
210 #pragma omp for simd private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
211   for (int k = 0; k < argc; ++k)
212     ++k;
213 #pragma omp for simd shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp for simd'}}
214   for (int k = 0; k < argc; ++k)
215     ++k;
216 #pragma omp parallel
217   {
218     int i;
219 #pragma omp for simd private(i)
220     for (int k = 0; k < argc; ++k)
221       ++k;
222   }
223 #pragma omp parallel shared(i)
224 #pragma omp parallel private(i)
225 #pragma omp for simd private(j)
226   for (int k = 0; k < argc; ++k)
227     ++k;
228 #pragma omp for simd private(i)
229   for (int k = 0; k < argc; ++k)
230     ++k;
231   static int m;
232 #pragma omp for simd private(m)
233   for (int k = 0; k < argc; ++k)
234     m = k + 2;
235 
236   s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
237   s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float>>::operator=' requested here}}
238   return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
239 }
240 
241