blob: 3c8968299c4f42965328154f071c1bcb70e99e9c [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;
100 return a + b;
101}
102
103int main(int argc, char **argv) {
104 int a;
105 int &b = a; // expected-note 2 {{'b' defined here}}
106 S sa; // expected-note 3 {{'sa' defined here}}
107 S &sb = sa; // expected-note 2 {{'sb' defined here}}
108 int r;
109#pragma omp task { // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
110 foo();
111#pragma omp task( // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
112 foo();
113#pragma omp task[ // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
114 foo();
115#pragma omp task] // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
116 foo();
117#pragma omp task) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
118 foo();
119#pragma omp task } // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
120 foo();
121#pragma omp task
122// expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}}
123#pragma omp task unknown()
124 foo();
125L1:
126 foo();
127#pragma omp task
128 ;
129#pragma omp task
130 {
131 goto L1; // expected-error {{use of undeclared label 'L1'}}
132 argc++;
133 }
134
135 for (int i = 0; i < 10; ++i) {
136 switch (argc) {
137 case (0):
138#pragma omp task
139 {
140 foo();
141 break; // expected-error {{'break' statement not in loop or switch statement}}
142 continue; // expected-error {{'continue' statement not in loop statement}}
143 }
144 default:
145 break;
146 }
147 }
148#pragma omp task default(none)
149 ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
150
151 goto L2; // expected-error {{use of undeclared label 'L2'}}
152#pragma omp task
153L2:
154 foo();
155#pragma omp task
156 {
157 return 1; // expected-error {{cannot return from OpenMP region}}
158 }
159
160 [[]] // expected-error {{an attribute list cannot appear here}}
161#pragma omp task
162 for (int n = 0; n < 100; ++n) {
163 }
164
165#pragma omp task default(none)
166#pragma omp task default(shared)
167 ++a;
168#pragma omp task default(none)
169#pragma omp task
170 ++a;
171#pragma omp task default(shared)
172#pragma omp task
173 ++a;
174#pragma omp task
175#pragma omp parallel
176 ++a;
177// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'int &'}}
178#pragma omp task
179 // expected-note@+1 {{used here}}
180 ++b;
181// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'int &'}}
182#pragma omp task
183// expected-note@+1 {{used here}}
184#pragma omp parallel shared(a, b)
185 ++a, ++b;
186#pragma omp task default(none)
187#pragma omp task default(shared)
188 ++sa;
189#pragma omp task default(none)
190// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
191#pragma omp task
192// expected-note@+1 {{used here}}
193 ++sa;
194#pragma omp task
195// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
196#pragma omp task
197// expected-note@+1 {{used here}}
198 ++sa;
199#pragma omp task default(shared)
200#pragma omp task
201 ++sa;
202#pragma omp task
203#pragma omp parallel
204 ++sa;
205// expected-error@+1 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
206#pragma omp task
207 // expected-note@+1 {{used here}}
208 ++sb;
209// expected-error@+2 {{predetermined as a firstprivate in a task construct variable cannot be of reference type 'S &'}}
210// expected-error@+1 {{predetermined as a firstprivate in a task construct variable must have an accessible, unambiguous copy constructor}}
211#pragma omp task
212// expected-note@+1 2 {{used here}}
213#pragma omp parallel shared(sa, sb)
214 ++sa, ++sb;
215// expected-note@+1 2 {{defined as reduction}}
216#pragma omp parallel reduction(+ : r)
217// expected-error@+1 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
218#pragma omp task firstprivate(r)
219 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
220 ++r;
221// expected-note@+1 {{defined as reduction}}
222#pragma omp parallel reduction(+ : r)
223#pragma omp task default(shared)
224 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
225 ++r;
226// expected-note@+1 {{defined as reduction}}
227#pragma omp parallel reduction(+ : r)
228#pragma omp task
229 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
230 ++r;
231#pragma omp parallel
232// expected-note@+1 2 {{defined as reduction}}
233#pragma omp for reduction(+ : r)
234 for (int i = 0; i < 10; ++i)
235// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
236#pragma omp task firstprivate(r)
237 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
238 ++r;
239#pragma omp parallel
240// expected-note@+1 {{defined as reduction}}
241#pragma omp for reduction(+ : r)
242 for (int i = 0; i < 10; ++i)
243#pragma omp task default(shared)
244 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
245 ++r;
246#pragma omp parallel
247// expected-note@+1 {{defined as reduction}}
248#pragma omp for reduction(+ : r)
249 for (int i = 0; i < 10; ++i)
250#pragma omp task
251 // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
252 ++r;
253// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
254#pragma omp task
255// expected-error@+2 {{reduction variable must be shared}}
256// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
257#pragma omp for reduction(+ : r)
258 ++r;
259 // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}
260 // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}
261 return foo<int>() + foo<S>();
262}
263