Clang Project

clang_source_code/test/OpenMP/task_messages.cpp
1// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s
2
3// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s
4
5void foo() {
6}
7
8#pragma omp task // expected-error {{unexpected OpenMP directive '#pragma omp task'}}
9
10class S {
11  S(const S &s) { a = s.a + 12; } // expected-note 16 {{implicitly declared private here}}
12  int a;
13
14public:
15  S() : a(0) {}
16  S(int a) : a(a) {}
17  operator int() { return a; }
18  S &operator++() { return *this; }
19  S operator+(const S &) { return *this; }
20};
21
22class S1 {
23  int a;
24
25public:
26  S1() : a(0) {}
27  S1 &operator++() { return *this; }
28  S1(const S1 &) = delete; // expected-note 2 {{'S1' has been explicitly marked deleted here}}
29};
30
31template <class T>
32int foo() {
33  T a;
34  T &b = a;
35  int r;
36  S1 s1;
37// expected-error@+1 2 {{call to deleted constructor of 'S1'}}
38#pragma omp task
39// expected-note@+1 2 {{predetermined as a firstprivate in a task construct here}}
40  ++s1;
41#pragma omp task default(none)
42#pragma omp task default(shared)
43  ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}}
44#pragma omp task default(none)
45#pragma omp task
46  // expected-error@+1 {{calling a private constructor of class 'S'}}
47  ++a; // expected-error 2 {{variable 'a' must have explicitly specified data sharing attributes}}
48#pragma omp task
49#pragma omp task
50  // expected-error@+1 {{calling a private constructor of class 'S'}}
51  ++a; // expected-error {{calling a private constructor of class 'S'}}
52#pragma omp task default(shared)
53#pragma omp task
54  // expected-error@+1 {{calling a private constructor of class 'S'}}
55  ++a;
56#pragma omp parallel shared(a)
57#pragma omp task
58#pragma omp task
59  ++a;
60#pragma omp parallel shared(a)
61#pragma omp task default(shared)
62#pragma omp task
63  ++a;
64#pragma omp task
65#pragma omp parallel
66  ++a; // expected-error {{calling a private constructor of class 'S'}}
67// expected-error@+2 {{calling a private constructor of class 'S'}}
68#pragma omp task
69  ++b;
70#pragma omp task
71// expected-error@+1 2 {{calling a private constructor of class 'S'}}
72#pragma omp parallel shared(a, b)
73  ++a, ++b;
74// expected-note@+1 2 {{defined as reduction}}
75#pragma omp parallel reduction(+ : r)
76// expected-error@+1 2 {{argument of a reduction clause of a parallel construct must not appear in a firstprivate clause on a task construct}}
77#pragma omp task firstprivate(r)
78  ++r;
79// expected-note@+1 2 {{defined as reduction}}
80#pragma omp parallel reduction(+ : r)
81#pragma omp task default(shared)
82  // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
83  ++r;
84// expected-note@+1 2 {{defined as reduction}}
85#pragma omp parallel reduction(+ : r)
86#pragma omp task
87  // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
88  ++r;
89#pragma omp parallel
90// expected-note@+1 2 {{defined as reduction}}
91#pragma omp for reduction(+ : r)
92  for (int i = 0; i < 10; ++i)
93// expected-error@+1 2 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
94#pragma omp task firstprivate(r)
95    ++r;
96#pragma omp parallel
97// expected-note@+1 2 {{defined as reduction}}
98#pragma omp for reduction(+ : r)
99  for (int i = 0; i < 10; ++i)
100#pragma omp task default(shared)
101    // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
102    ++r;
103#pragma omp parallel
104// expected-note@+1 2 {{defined as reduction}}
105#pragma omp for reduction(+ : r)
106  for (int i = 0; i < 10; ++i)
107#pragma omp task
108    // expected-error@+1 2 {{reduction variables may not be accessed in an explicit task}}
109    ++r;
110// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
111#pragma omp task
112// expected-error@+2 {{reduction variable must be shared}}
113// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
114#pragma omp for reduction(+ : r)
115  ++r;
116// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
117#pragma omp task untied untied
118  ++r;
119// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
120#pragma omp task mergeable mergeable
121  ++r;
122  return a + b;
123}
124
125int main(int argc, char **argv) {
126  int a;
127  int &b = a;
128  S sa;
129  S &sb = sa;
130  int r;
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) // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
140  foo();
141#pragma omp task } // expected-warning {{extra tokens at the end of '#pragma omp task' are ignored}}
142  foo();
143#pragma omp task
144// expected-warning@+1 {{extra tokens at the end of '#pragma omp task' are ignored}}
145#pragma omp task unknown()
146  foo();
147L1:
148  foo();
149#pragma omp task
150  ;
151#pragma omp task
152  {
153    goto L1; // expected-error {{use of undeclared label 'L1'}}
154    argc++;
155  }
156
157  for (int i = 0; i < 10; ++i) {
158    switch (argc) {
159    case (0):
160#pragma omp task
161    {
162      foo();
163      break;    // expected-error {{'break' statement not in loop or switch statement}}
164      continue; // expected-error {{'continue' statement not in loop statement}}
165    }
166    default:
167      break;
168    }
169  }
170#pragma omp task default(none)
171  ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
172
173  goto L2; // expected-error {{use of undeclared label 'L2'}}
174#pragma omp task
175L2:
176  foo();
177#pragma omp task
178  {
179    return 1; // expected-error {{cannot return from OpenMP region}}
180  }
181
182  [[]] // expected-error {{an attribute list cannot appear here}}
183#pragma omp task
184      for (int n = 0; n < 100; ++n) {
185  }
186
187#pragma omp task default(none)
188#pragma omp task default(shared)
189  ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}
190#pragma omp task default(none)
191#pragma omp task
192  ++a; // expected-error {{variable 'a' must have explicitly specified data sharing attributes}}
193#pragma omp task default(shared)
194#pragma omp task
195  ++a;
196#pragma omp task
197#pragma omp parallel
198  ++a;
199#pragma omp task
200  ++b;
201#pragma omp task
202#pragma omp parallel shared(a, b)
203  ++a, ++b;
204#pragma omp task default(none)
205#pragma omp task default(shared)
206  ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}}
207#pragma omp task default(none)
208#pragma omp task
209  // expected-error@+1 {{calling a private constructor of class 'S'}}
210  ++sa; // expected-error {{variable 'sa' must have explicitly specified data sharing attributes}}
211#pragma omp task
212#pragma omp task
213  // expected-error@+1 {{calling a private constructor of class 'S'}}
214  ++sa; // expected-error {{calling a private constructor of class 'S'}}
215#pragma omp task default(shared)
216#pragma omp task
217  // expected-error@+1 {{calling a private constructor of class 'S'}}
218  ++sa;
219#pragma omp parallel shared(sa)
220#pragma omp task
221#pragma omp task
222  ++sa;
223#pragma omp parallel shared(sa)
224#pragma omp task default(shared)
225#pragma omp task
226  ++sa;
227#pragma omp task
228#pragma omp parallel
229  ++sa; // expected-error {{calling a private constructor of class 'S'}}
230// expected-error@+2 {{calling a private constructor of class 'S'}}
231#pragma omp task
232  ++sb;
233// expected-error@+2 2 {{calling a private constructor of class 'S'}}
234#pragma omp task
235#pragma omp parallel shared(sa, sb)
236  ++sa, ++sb;
237// expected-note@+1 2 {{defined as reduction}}
238#pragma omp parallel reduction(+ : r)
239// expected-error@+1 {{argument of a reduction clause of a parallel 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// expected-note@+1 {{defined as reduction}}
244#pragma omp parallel reduction(+ : r)
245#pragma omp task default(shared)
246  // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
247  ++r;
248// expected-note@+1 {{defined as reduction}}
249#pragma omp parallel reduction(+ : r)
250#pragma omp task
251  // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
252  ++r;
253#pragma omp parallel
254// expected-note@+1 2 {{defined as reduction}}
255#pragma omp for reduction(+ : r)
256  for (int i = 0; i < 10; ++i)
257// expected-error@+1 {{argument of a reduction clause of a for construct must not appear in a firstprivate clause on a task construct}}
258#pragma omp task firstprivate(r)
259    // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
260    ++r;
261#pragma omp parallel
262// expected-note@+1 {{defined as reduction}}
263#pragma omp for reduction(+ : r)
264  for (int i = 0; i < 10; ++i)
265#pragma omp task default(shared)
266    // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
267    ++r;
268#pragma omp parallel
269// expected-note@+1 {{defined as reduction}}
270#pragma omp for reduction(+ : r)
271  for (int i = 0; i < 10; ++i)
272#pragma omp task
273    // expected-error@+1 {{reduction variables may not be accessed in an explicit task}}
274    ++r;
275// expected-note@+1 {{non-shared variable in a task construct is predetermined as firstprivate}}
276#pragma omp task
277// expected-error@+2 {{reduction variable must be shared}}
278// expected-error@+1 {{region cannot be closely nested inside 'task' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
279#pragma omp for reduction(+ : r)
280  ++r;
281// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
282#pragma omp task untied untied
283  ++r;
284// expected-error@+1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
285#pragma omp task mergeable mergeable
286  ++r;
287  // expected-note@+2 {{in instantiation of function template specialization 'foo<int>' requested here}}
288  // expected-note@+1 {{in instantiation of function template specialization 'foo<S>' requested here}}
289  return foo<int>() + foo<S>();
290}
291
292