1 // RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
4 
5 void xxx(int argc) {
6   int x; // expected-note {{initialize the variable 'x' to silence this warning}}
7 #pragma omp task
8   argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
9 }
10 
11 void foo() {
12 }
13 
14 #pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}}
15 
16 class S {
17   S(const S &s) { a = s.a + 12; } // expected-note 16 {{implicitly declared private here}}
18   int a;
19 
20 public:
21   S() : a(0) {}
22   S(int a) : a(a) {}
23   operator int() { return a; }
24   S &operator++() { return *this; }
25   S operator+(const S &) { return *this; }
26 };
27 
28 class S1 {
29   int a;
30 
31 public:
32   S1() : a(0) {}
33   S1 &operator++() { return *this; }
34   S1(const S1 &) = delete; // expected-note 2 {{'S1' has been explicitly marked deleted here}}
35 };
36 
37 template <class T>
38 int foo() {
39   T a;
40   T &b = a;
41   int r;
42   S1 s1;
43 // expected-error@+1 2 {{call to deleted constructor of 'S1'}}
44 #pragma omp task
45 // expected-note@+1 2 {{predetermined as a firstprivate in a task construct here}}
46   ++s1;
47 #pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}}
48 #pragma omp task default(shared)
49   ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}}
50 #pragma omp task default(none) // expected-note 2 {{explicit data sharing attribute requested here}}
51 #pragma omp task
52   // expected-error@+1 {{calling a private constructor of class 'S'}}
53   ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}}
54 #pragma omp task
55 #pragma omp task
56   // expected-error@+1 {{calling a private constructor of class 'S'}}
57   ++a; // expected-error {{calling a private constructor of class 'S'}}
58 #pragma omp task default(shared)
59 #pragma omp task
60   // expected-error@+1 {{calling a private constructor of class 'S'}}
61   ++a;
62 #pragma omp parallel shared(a)
63 #pragma omp task
64 #pragma omp task
65   ++a;
66 #pragma omp parallel shared(a)
67 #pragma omp task default(shared)
68 #pragma omp task
69   ++a;
70 #pragma omp task
71 #pragma omp parallel
72   ++a; // expected-error {{calling a private constructor of class 'S'}}
73 // expected-error@+2 {{calling a private constructor of class 'S'}}
74 #pragma omp task
75   ++b;
76 #pragma omp task
77 // expected-error@+1 2 {{calling a private constructor of class 'S'}}
78 #pragma omp parallel shared(a, b)
79   ++a, ++b;
80 // expected-note@+1 2 {{defined as reduction}}
81 #pragma omp parallel reduction(+ : r)
82 // expected-error@+1 2 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
83 #pragma omp task firstprivate(r)
84   ++r;
85 // expected-note@+1 2 {{defined as reduction}}
86 #pragma omp parallel reduction(+ : r)
87 #pragma omp task default(shared)
88   // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
89   ++r;
90 // expected-note@+1 2 {{defined as reduction}}
91 #pragma omp parallel reduction(+ : r)
92 #pragma omp task
93   // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
94   ++r;
95 #pragma omp parallel
96 // expected-note@+1 2 {{defined as reduction}}
97 #pragma omp for reduction(+ : r)
98   for (int i = 0; i < 10; ++i)
99 // expected-error@+1 2 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
100 #pragma omp task firstprivate(r)
101     ++r;
102 #pragma omp parallel
103 // expected-note@+1 2 {{defined as reduction}}
104 #pragma omp for reduction(+ : r)
105   for (int i = 0; i < 10; ++i)
106 #pragma omp task default(shared)
107     // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
108     ++r;
109 #pragma omp parallel
110 // expected-note@+1 2 {{defined as reduction}}
111 #pragma omp for reduction(+ : r)
112   for (int i = 0; i < 10; ++i)
113 #pragma omp task
114     // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
115     ++r;
116 // expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
117 #pragma omp task
118 // expected-error@+2 {{reduction variable must be shared}}
119 // expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
120 #pragma omp for reduction(+ : r)
121   ++r;
122 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
123 #pragma omp task untied untied
124   ++r;
125 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
126 #pragma omp task mergeable mergeable
127   ++r;
128   return a + b;
129 }
130 
131 int main(int argc, char **argv) {
132   int a;
133   int &b = a;
134   S sa;
135   S &sb = sa;
136   int r;
137 #pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
138   foo();
139 #pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
140   foo();
141 #pragma omp task[ // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
142   foo();
143 #pragma omp task] // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
144   foo();
145 #pragma omp task) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
146   foo();
147 #pragma omp task } // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
148   foo();
149 #pragma omp task
150 // expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}}
151 #pragma omp task unknown()
152   foo();
153 L1:
154   foo();
155 #pragma omp task
156   ;
157 #pragma omp task
158   {
159     goto L1; // expected-error {{use of undeclared label 'L1'}}
160     argc++;
161   }
162 
163   for (int i = 0; i < 10; ++i) {
164     switch (argc) {
165     case (0):
166 #pragma omp task
167     {
168       foo();
169       break;    // expected-error {{'break' statement not in loop or switch statement}}
170       continue; // expected-error {{'continue' statement not in loop statement}}
171     }
172     default:
173       break;
174     }
175   }
176 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}
177   ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
178 
179   goto L2; // expected-error {{use of undeclared label 'L2'}}
180 #pragma omp task
181 L2:
182   foo();
183 #pragma omp task
184   {
185     return 1; // expected-error {{cannot return from OpenMP region}}
186   }
187 
188   [[]] // expected-error {{an attribute list cannot appear here}}
189 #pragma omp task
190       for (int n = 0; n < 100; ++n) {
191   }
192 
193 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}
194 #pragma omp task default(shared)
195   ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}
196 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}
197 #pragma omp task
198   ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}
199 #pragma omp task default(shared)
200 #pragma omp task
201   ++a;
202 #pragma omp task
203 #pragma omp parallel
204   ++a;
205 #pragma omp task
206   ++b;
207 #pragma omp task
208 #pragma omp parallel shared(a, b)
209   ++a, ++b;
210 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}
211 #pragma omp task default(shared)
212   ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}}
213 #pragma omp task default(none) // expected-note {{explicit data sharing attribute requested here}}
214 #pragma omp task
215   // expected-error@+1 {{calling a private constructor of class 'S'}}
216   ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}}
217 #pragma omp task
218 #pragma omp task
219   // expected-error@+1 {{calling a private constructor of class 'S'}}
220   ++sa; // expected-error {{calling a private constructor of class 'S'}}
221 #pragma omp task default(shared)
222 #pragma omp task
223   // expected-error@+1 {{calling a private constructor of class 'S'}}
224   ++sa;
225 #pragma omp parallel shared(sa)
226 #pragma omp task
227 #pragma omp task
228   ++sa;
229 #pragma omp parallel shared(sa)
230 #pragma omp task default(shared)
231 #pragma omp task
232   ++sa;
233 #pragma omp task
234 #pragma omp parallel
235   ++sa; // expected-error {{calling a private constructor of class 'S'}}
236 // expected-error@+2 {{calling a private constructor of class 'S'}}
237 #pragma omp task
238   ++sb;
239 // expected-error@+2 2 {{calling a private constructor of class 'S'}}
240 #pragma omp task
241 #pragma omp parallel shared(sa, sb)
242   ++sa, ++sb;
243 // expected-note@+1 2 {{defined as reduction}}
244 #pragma omp parallel reduction(+ : r)
245 // expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
246 #pragma omp task firstprivate(r)
247   // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
248   ++r;
249 // expected-note@+1 {{defined as reduction}}
250 #pragma omp parallel reduction(+ : r)
251 #pragma omp task default(shared)
252   // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
253   ++r;
254 // expected-note@+1 {{defined as reduction}}
255 #pragma omp parallel reduction(+ : r)
256 #pragma omp task
257   // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
258   ++r;
259 #pragma omp parallel
260 // expected-note@+1 2 {{defined as reduction}}
261 #pragma omp for reduction(+ : r)
262   for (int i = 0; i < 10; ++i)
263 // expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
264 #pragma omp task firstprivate(r)
265     // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
266     ++r;
267 #pragma omp parallel
268 // expected-note@+1 {{defined as reduction}}
269 #pragma omp for reduction(+ : r)
270   for (int i = 0; i < 10; ++i)
271 #pragma omp task default(shared)
272     // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
273     ++r;
274 #pragma omp parallel
275 // expected-note@+1 {{defined as reduction}}
276 #pragma omp for reduction(+ : r)
277   for (int i = 0; i < 10; ++i)
278 #pragma omp task
279     // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
280     ++r;
281 // expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
282 #pragma omp task
283 // expected-error@+2 {{reduction variable must be shared}}
284 // expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
285 #pragma omp for reduction(+ : r)
286   ++r;
287 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
288 #pragma omp task untied untied
289   ++r;
290 // expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
291 #pragma omp task mergeable mergeable
292   ++r;
293   // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}
294   // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}
295   return foo<int>() + foo<S>();
296 }
297 
298