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