blob: f42a37ae1daad175ca8b9d28633b81020c65d05f [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002
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 {
Alexey Bataevbd9fec12015-08-18 06:47:21 +00009 S(const S &s) { a = s.a + 12; } // expected-note 10 {{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 Bataevbd9fec12015-08-18 06:47:21 +000032 T &b = a;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000033 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;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000056// expected-error@+2 {{calling a private constructor of class 'S'}}
Alexey Bataevbd9fec12015-08-18 06:47:21 +000057#pragma omp task
58 ++b;
59#pragma omp task
60// expected-error@+1 2 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000061#pragma omp parallel shared(a, b)
62 ++a, ++b;
Alexey Bataeva839ddd2016-03-17 10:19:46 +000063// expected-note@+1 2 {{defined as reduction}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000064#pragma omp parallel reduction(+ : r)
Alexey Bataeva839ddd2016-03-17 10:19:46 +000065// expected-error@+1 2 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000066#pragma omp task firstprivate(r)
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000067 ++r;
68// expected-note@+1 2 {{defined as reduction}}
69#pragma omp parallel reduction(+ : r)
70#pragma omp task default(shared)
71 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
72 ++r;
73// expected-note@+1 2 {{defined as reduction}}
74#pragma omp parallel reduction(+ : r)
75#pragma omp task
76 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
77 ++r;
78#pragma omp parallel
Alexey Bataeva839ddd2016-03-17 10:19:46 +000079// expected-note@+1 2 {{defined as reduction}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000080#pragma omp for reduction(+ : r)
81 for (int i = 0; i < 10; ++i)
Alexey Bataeva839ddd2016-03-17 10:19:46 +000082// expected-error@+1 2 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000083#pragma omp task firstprivate(r)
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +000084 ++r;
85#pragma omp parallel
86// expected-note@+1 2 {{defined as reduction}}
87#pragma omp for reduction(+ : r)
88 for (int i = 0; i < 10; ++i)
89#pragma omp task default(shared)
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
97 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
98 ++r;
99// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
100#pragma omp task
101// expected-error@+2 {{reduction variable must be shared}}
102// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
103#pragma omp for reduction(+ : r)
104 ++r;
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000105// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
106#pragma omp task untied untied
107 ++r;
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000108// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
109#pragma omp task mergeable mergeable
110 ++r;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000111 return a + b;
112}
113
114int main(int argc, char **argv) {
115 int a;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000116 int &b = a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000117 S sa;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000118 S &sb = sa;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000119 int r;
120#pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
121 foo();
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
133// expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}}
134#pragma omp task unknown()
135 foo();
136L1:
137 foo();
138#pragma omp task
139 ;
140#pragma omp task
141 {
142 goto L1; // expected-error {{use of undeclared label 'L1'}}
143 argc++;
144 }
145
146 for (int i = 0; i < 10; ++i) {
147 switch (argc) {
148 case (0):
149#pragma omp task
150 {
151 foo();
152 break; // expected-error {{'break' statement not in loop or switch statement}}
153 continue; // expected-error {{'continue' statement not in loop statement}}
154 }
155 default:
156 break;
157 }
158 }
159#pragma omp task default(none)
160 ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
161
162 goto L2; // expected-error {{use of undeclared label 'L2'}}
163#pragma omp task
164L2:
165 foo();
166#pragma omp task
167 {
168 return 1; // expected-error {{cannot return from OpenMP region}}
169 }
170
171 [[]] // expected-error {{an attribute list cannot appear here}}
172#pragma omp task
173 for (int n = 0; n < 100; ++n) {
174 }
175
176#pragma omp task default(none)
177#pragma omp task default(shared)
178 ++a;
179#pragma omp task default(none)
180#pragma omp task
181 ++a;
182#pragma omp task default(shared)
183#pragma omp task
184 ++a;
185#pragma omp task
186#pragma omp parallel
187 ++a;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000188#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000189 ++b;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000190#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000191#pragma omp parallel shared(a, b)
192 ++a, ++b;
193#pragma omp task default(none)
194#pragma omp task default(shared)
195 ++sa;
196#pragma omp task default(none)
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000197#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000198 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000199 ++sa;
200#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000201#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000202 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000203 ++sa;
204#pragma omp task default(shared)
205#pragma omp task
206 ++sa;
207#pragma omp task
208#pragma omp parallel
209 ++sa;
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000210// expected-error@+2 {{calling a private constructor of class 'S'}}
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000211#pragma omp task
212 ++sb;
213// expected-error@+2 2 {{calling a private constructor of class 'S'}}
214#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000215#pragma omp parallel shared(sa, sb)
216 ++sa, ++sb;
217// expected-note@+1 2 {{defined as reduction}}
218#pragma omp parallel reduction(+ : r)
219// expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
220#pragma omp task firstprivate(r)
221 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
222 ++r;
223// expected-note@+1 {{defined as reduction}}
224#pragma omp parallel reduction(+ : r)
225#pragma omp task default(shared)
226 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
227 ++r;
228// expected-note@+1 {{defined as reduction}}
229#pragma omp parallel reduction(+ : r)
230#pragma omp task
231 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
232 ++r;
233#pragma omp parallel
234// expected-note@+1 2 {{defined as reduction}}
235#pragma omp for reduction(+ : r)
236 for (int i = 0; i < 10; ++i)
237// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
238#pragma omp task firstprivate(r)
239 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
240 ++r;
241#pragma omp parallel
242// expected-note@+1 {{defined as reduction}}
243#pragma omp for reduction(+ : r)
244 for (int i = 0; i < 10; ++i)
245#pragma omp task default(shared)
246 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
247 ++r;
248#pragma omp parallel
249// expected-note@+1 {{defined as reduction}}
250#pragma omp for reduction(+ : r)
251 for (int i = 0; i < 10; ++i)
252#pragma omp task
253 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
254 ++r;
255// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
256#pragma omp task
257// expected-error@+2 {{reduction variable must be shared}}
258// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
259#pragma omp for reduction(+ : r)
260 ++r;
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000261// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
262#pragma omp task untied untied
263 ++r;
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000264// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
265#pragma omp task mergeable mergeable
266 ++r;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000267 // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}
268 // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}
269 return foo<int>() + foo<S>();
270}
271