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