blob: 64bf8a40f025da11baaf4143bec1ec41e95479cc [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;
63// expected-note@+1 3 {{defined as reduction}}
64#pragma omp parallel reduction(+ : r)
65// expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
66#pragma omp task firstprivate(r)
67 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
68 ++r;
69// expected-note@+1 2 {{defined as reduction}}
70#pragma omp parallel reduction(+ : r)
71#pragma omp task default(shared)
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
77 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
78 ++r;
79#pragma omp parallel
80// expected-note@+1 3 {{defined as reduction}}
81#pragma omp for reduction(+ : r)
82 for (int i = 0; i < 10; ++i)
83// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
84#pragma omp task firstprivate(r)
85 // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
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;
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000107// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
108#pragma omp task untied untied
109 ++r;
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000110// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
111#pragma omp task mergeable mergeable
112 ++r;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000113 return a + b;
114}
115
116int main(int argc, char **argv) {
117 int a;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000118 int &b = a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000119 S sa;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000120 S &sb = sa;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000121 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();
138L1:
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
166L2:
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;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000190#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000191 ++b;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000192#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000193#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)
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000199#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000200 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000201 ++sa;
202#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000203#pragma omp task
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000204 // expected-error@+1 {{calling a private constructor of class 'S'}}
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000205 ++sa;
206#pragma omp task default(shared)
207#pragma omp task
208 ++sa;
209#pragma omp task
210#pragma omp parallel
211 ++sa;
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000212// expected-error@+2 {{calling a private constructor of class 'S'}}
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000213#pragma omp task
214 ++sb;
215// expected-error@+2 2 {{calling a private constructor of class 'S'}}
216#pragma omp task
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000217#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;
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000263// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
264#pragma omp task untied untied
265 ++r;
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000266// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
267#pragma omp task mergeable mergeable
268 ++r;
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000269 // 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