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