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