blob: b02b43c2b3950c71829d121b9eb7daf79f2c126f [file] [log] [blame]
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00001// RUN: %clang_cc1 -verify -fopenmp=libiomp5 -ferror-limit 100 -std=c++11 -o - %s
2
3void foo() {
4}
5
6#pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}}
7
Alexey Bataev4a5bb772014-10-08 14:01:46 +00008class S {
9 S(const S &s) { a = s.a + 12; } // expected-note 6 {{implicitly declared private here}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000010 int a;
11
12public:
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
Alexey Bataev4a5bb772014-10-08 14:01:46 +000020class S1 {
21 int a;
22
23public:
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
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000029template <class T>
30int foo() {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000031 T a;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000032 T &b = a; // expected-note 4 {{'b' defined here}}
33 int r;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000034 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;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000039#pragma omp task default(none)
40#pragma omp task default(shared)
41 ++a;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000042#pragma omp task default(none)
43#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +000044 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000045 ++a;
46#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000047#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +000048 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000049 ++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;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000061// 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 &'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000063#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +000064// expected-error@+2 {{calling a private constructor of class 'S'}}
65// expected-note@+1 2 {{used here}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000066#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;
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000112// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
113#pragma omp task untied untied
114 ++r;
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000115// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
116#pragma omp task mergeable mergeable
117 ++r;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000118 return a + b;
119}
120
121int main(int argc, char **argv) {
122 int a;
123 int &b = a; // expected-note 2 {{'b' defined here}}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000124 S sa;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000125 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();
143L1:
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
171L2:
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)
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000208#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000209 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000210 ++sa;
211#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000212#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000213 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000214 ++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;
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000225// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000226#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000227// expected-error@+2 {{calling a private constructor of class 'S'}}
228// expected-note@+1 {{used here}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000229#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;
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000275// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
276#pragma omp task untied untied
277 ++r;
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000278// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
279#pragma omp task mergeable mergeable
280 ++r;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000281 // 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