blob: 7a924b4ce2bfa49c6d9fd9b179fbdd637d3dd015 [file] [log] [blame]
Alexey Bataeva769e072013-03-22 06:34:35 +00001//===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10/// \brief This file implements parsing of all OpenMP directives and clauses.
11///
12//===----------------------------------------------------------------------===//
13
Chandler Carruth5553d0d2014-01-07 11:51:46 +000014#include "RAIIObjectsForParser.h"
Alexey Bataev9959db52014-05-06 10:08:46 +000015#include "clang/AST/ASTConsumer.h"
16#include "clang/AST/ASTContext.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000017#include "clang/AST/StmtOpenMP.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000018#include "clang/Parse/ParseDiagnostic.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000019#include "clang/Parse/Parser.h"
20#include "clang/Sema/Scope.h"
21#include "llvm/ADT/PointerIntPair.h"
Michael Wong65f367f2015-07-21 13:44:28 +000022
Alexey Bataeva769e072013-03-22 06:34:35 +000023using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// OpenMP declarative directives.
27//===----------------------------------------------------------------------===//
28
Dmitry Polukhin82478332016-02-13 06:53:38 +000029namespace {
30enum OpenMPDirectiveKindEx {
31 OMPD_cancellation = OMPD_unknown + 1,
32 OMPD_data,
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000033 OMPD_declare,
Dmitry Polukhin82478332016-02-13 06:53:38 +000034 OMPD_enter,
35 OMPD_exit,
36 OMPD_point,
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000037 OMPD_reduction,
Dmitry Polukhin82478332016-02-13 06:53:38 +000038 OMPD_target_enter,
39 OMPD_target_exit
40};
41} // namespace
42
43// Map token string to extended OMP token kind that are
44// OpenMPDirectiveKind + OpenMPDirectiveKindEx.
45static unsigned getOpenMPDirectiveKindEx(StringRef S) {
46 auto DKind = getOpenMPDirectiveKind(S);
47 if (DKind != OMPD_unknown)
48 return DKind;
49
50 return llvm::StringSwitch<unsigned>(S)
51 .Case("cancellation", OMPD_cancellation)
52 .Case("data", OMPD_data)
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000053 .Case("declare", OMPD_declare)
Dmitry Polukhin82478332016-02-13 06:53:38 +000054 .Case("enter", OMPD_enter)
55 .Case("exit", OMPD_exit)
56 .Case("point", OMPD_point)
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000057 .Case("reduction", OMPD_reduction)
Dmitry Polukhin82478332016-02-13 06:53:38 +000058 .Default(OMPD_unknown);
59}
60
Alexey Bataev4acb8592014-07-07 13:01:15 +000061static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
Alexander Musmanf82886e2014-09-18 05:12:34 +000062 // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
63 // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
64 // TODO: add other combined directives in topological order.
Dmitry Polukhin82478332016-02-13 06:53:38 +000065 static const unsigned F[][3] = {
66 { OMPD_cancellation, OMPD_point, OMPD_cancellation_point },
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000067 { OMPD_declare, OMPD_reduction, OMPD_declare_reduction },
Dmitry Polukhin82478332016-02-13 06:53:38 +000068 { OMPD_target, OMPD_data, OMPD_target_data },
69 { OMPD_target, OMPD_enter, OMPD_target_enter },
70 { OMPD_target, OMPD_exit, OMPD_target_exit },
71 { OMPD_target_enter, OMPD_data, OMPD_target_enter_data },
72 { OMPD_target_exit, OMPD_data, OMPD_target_exit_data },
73 { OMPD_for, OMPD_simd, OMPD_for_simd },
74 { OMPD_parallel, OMPD_for, OMPD_parallel_for },
75 { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd },
76 { OMPD_parallel, OMPD_sections, OMPD_parallel_sections },
77 { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd },
78 { OMPD_target, OMPD_parallel, OMPD_target_parallel },
79 { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for }
80 };
Alexey Bataev94a4f0c2016-03-03 05:21:39 +000081 enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 };
Alexey Bataev4acb8592014-07-07 13:01:15 +000082 auto Tok = P.getCurToken();
Dmitry Polukhin82478332016-02-13 06:53:38 +000083 unsigned DKind =
Alexey Bataev4acb8592014-07-07 13:01:15 +000084 Tok.isAnnotation()
Dmitry Polukhin82478332016-02-13 06:53:38 +000085 ? static_cast<unsigned>(OMPD_unknown)
86 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
87 if (DKind == OMPD_unknown)
88 return OMPD_unknown;
Michael Wong65f367f2015-07-21 13:44:28 +000089
Alexander Musmanf82886e2014-09-18 05:12:34 +000090 for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
Dmitry Polukhin82478332016-02-13 06:53:38 +000091 if (DKind != F[i][0])
92 continue;
Michael Wong65f367f2015-07-21 13:44:28 +000093
Dmitry Polukhin82478332016-02-13 06:53:38 +000094 Tok = P.getPreprocessor().LookAhead(0);
95 unsigned SDKind =
96 Tok.isAnnotation()
97 ? static_cast<unsigned>(OMPD_unknown)
98 : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
99 if (SDKind == OMPD_unknown)
100 continue;
Michael Wong65f367f2015-07-21 13:44:28 +0000101
Dmitry Polukhin82478332016-02-13 06:53:38 +0000102 if (SDKind == F[i][1]) {
103 P.ConsumeToken();
104 DKind = F[i][2];
Alexey Bataev4acb8592014-07-07 13:01:15 +0000105 }
106 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000107 return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind)
108 : OMPD_unknown;
109}
110
111static DeclarationName parseOpenMPReductionId(Parser &P) {
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000112 Token Tok = P.getCurToken();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000113 Sema &Actions = P.getActions();
114 OverloadedOperatorKind OOK = OO_None;
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000115 // Allow to use 'operator' keyword for C++ operators
116 bool WithOperator = false;
117 if (Tok.is(tok::kw_operator)) {
118 P.ConsumeToken();
119 Tok = P.getCurToken();
120 WithOperator = true;
121 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000122 switch (Tok.getKind()) {
123 case tok::plus: // '+'
124 OOK = OO_Plus;
125 break;
126 case tok::minus: // '-'
127 OOK = OO_Minus;
128 break;
129 case tok::star: // '*'
130 OOK = OO_Star;
131 break;
132 case tok::amp: // '&'
133 OOK = OO_Amp;
134 break;
135 case tok::pipe: // '|'
136 OOK = OO_Pipe;
137 break;
138 case tok::caret: // '^'
139 OOK = OO_Caret;
140 break;
141 case tok::ampamp: // '&&'
142 OOK = OO_AmpAmp;
143 break;
144 case tok::pipepipe: // '||'
145 OOK = OO_PipePipe;
146 break;
147 case tok::identifier: // identifier
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000148 if (!WithOperator)
149 break;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000150 default:
151 P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier);
152 P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
153 Parser::StopBeforeMatch);
154 return DeclarationName();
155 }
156 P.ConsumeToken();
157 auto &DeclNames = Actions.getASTContext().DeclarationNames;
158 return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo())
159 : DeclNames.getCXXOperatorName(OOK);
160}
161
162/// \brief Parse 'omp declare reduction' construct.
163///
164/// declare-reduction-directive:
165/// annot_pragma_openmp 'declare' 'reduction'
166/// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')'
167/// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')']
168/// annot_pragma_openmp_end
169/// <reduction_id> is either a base language identifier or one of the following
170/// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'.
171///
172Parser::DeclGroupPtrTy
173Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) {
174 // Parse '('.
175 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
176 if (T.expectAndConsume(diag::err_expected_lparen_after,
177 getOpenMPDirectiveName(OMPD_declare_reduction))) {
178 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
179 return DeclGroupPtrTy();
180 }
181
182 DeclarationName Name = parseOpenMPReductionId(*this);
183 if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end))
184 return DeclGroupPtrTy();
185
186 // Consume ':'.
187 bool IsCorrect = !ExpectAndConsume(tok::colon);
188
189 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
190 return DeclGroupPtrTy();
191
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000192 IsCorrect = IsCorrect && !Name.isEmpty();
193
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000194 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) {
195 Diag(Tok.getLocation(), diag::err_expected_type);
196 IsCorrect = false;
197 }
198
199 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
200 return DeclGroupPtrTy();
201
202 SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes;
203 // Parse list of types until ':' token.
204 do {
205 ColonProtectionRAIIObject ColonRAII(*this);
206 SourceRange Range;
207 TypeResult TR = ParseTypeName(&Range, Declarator::PrototypeContext, AS);
208 if (TR.isUsable()) {
209 auto ReductionType =
210 Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR);
211 if (!ReductionType.isNull()) {
212 ReductionTypes.push_back(
213 std::make_pair(ReductionType, Range.getBegin()));
214 }
215 } else {
216 SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end,
217 StopBeforeMatch);
218 }
219
220 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end))
221 break;
222
223 // Consume ','.
224 if (ExpectAndConsume(tok::comma)) {
225 IsCorrect = false;
226 if (Tok.is(tok::annot_pragma_openmp_end)) {
227 Diag(Tok.getLocation(), diag::err_expected_type);
228 return DeclGroupPtrTy();
229 }
230 }
231 } while (Tok.isNot(tok::annot_pragma_openmp_end));
232
233 if (ReductionTypes.empty()) {
234 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
235 return DeclGroupPtrTy();
236 }
237
238 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
239 return DeclGroupPtrTy();
240
241 // Consume ':'.
242 if (ExpectAndConsume(tok::colon))
243 IsCorrect = false;
244
245 if (Tok.is(tok::annot_pragma_openmp_end)) {
246 Diag(Tok.getLocation(), diag::err_expected_expression);
247 return DeclGroupPtrTy();
248 }
249
250 DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart(
251 getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS);
252
253 // Parse <combiner> expression and then parse initializer if any for each
254 // correct type.
255 unsigned I = 0, E = ReductionTypes.size();
256 for (auto *D : DRD.get()) {
257 TentativeParsingAction TPA(*this);
258 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
259 Scope::OpenMPDirectiveScope);
260 // Parse <combiner> expression.
261 Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D);
262 ExprResult CombinerResult =
263 Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(),
264 D->getLocation(), /*DiscardedValue=*/true);
265 Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get());
266
267 if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
268 Tok.isNot(tok::annot_pragma_openmp_end)) {
269 TPA.Commit();
270 IsCorrect = false;
271 break;
272 }
273 IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable();
274 ExprResult InitializerResult;
275 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
276 // Parse <initializer> expression.
277 if (Tok.is(tok::identifier) &&
278 Tok.getIdentifierInfo()->isStr("initializer"))
279 ConsumeToken();
280 else {
281 Diag(Tok.getLocation(), diag::err_expected) << "'initializer'";
282 TPA.Commit();
283 IsCorrect = false;
284 break;
285 }
286 // Parse '('.
287 BalancedDelimiterTracker T(*this, tok::l_paren,
288 tok::annot_pragma_openmp_end);
289 IsCorrect =
290 !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") &&
291 IsCorrect;
292 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
293 ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope |
294 Scope::OpenMPDirectiveScope);
295 // Parse expression.
296 Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D);
297 InitializerResult = Actions.ActOnFinishFullExpr(
298 ParseAssignmentExpression().get(), D->getLocation(),
299 /*DiscardedValue=*/true);
300 Actions.ActOnOpenMPDeclareReductionInitializerEnd(
301 D, InitializerResult.get());
302 if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) &&
303 Tok.isNot(tok::annot_pragma_openmp_end)) {
304 TPA.Commit();
305 IsCorrect = false;
306 break;
307 }
308 IsCorrect =
309 !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid();
310 }
311 }
312
313 ++I;
314 // Revert parsing if not the last type, otherwise accept it, we're done with
315 // parsing.
316 if (I != E)
317 TPA.Revert();
318 else
319 TPA.Commit();
320 }
321 return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD,
322 IsCorrect);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000323}
324
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000325/// \brief Parsing of declarative OpenMP directives.
326///
327/// threadprivate-directive:
328/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000329/// annot_pragma_openmp_end
Alexey Bataeva769e072013-03-22 06:34:35 +0000330///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000331/// declare-reduction-directive:
332/// annot_pragma_openmp 'declare' 'reduction' [...]
333/// annot_pragma_openmp_end
334///
335Parser::DeclGroupPtrTy
336Parser::ParseOpenMPDeclarativeDirective(AccessSpecifier AS) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000337 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000338 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +0000339
340 SourceLocation Loc = ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000341 SmallVector<Expr *, 5> Identifiers;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000342 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000343
344 switch (DKind) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000345 case OMPD_threadprivate:
346 ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000347 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000348 // The last seen token is annot_pragma_openmp_end - need to check for
349 // extra tokens.
350 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
351 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000352 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000353 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +0000354 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000355 // Skip the last annot_pragma_openmp_end.
Alexey Bataeva769e072013-03-22 06:34:35 +0000356 ConsumeToken();
Alexey Bataeva55ed262014-05-28 06:15:33 +0000357 return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataeva769e072013-03-22 06:34:35 +0000358 }
359 break;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000360 case OMPD_declare_reduction:
361 ConsumeToken();
362 if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) {
363 // The last seen token is annot_pragma_openmp_end - need to check for
364 // extra tokens.
365 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
366 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
367 << getOpenMPDirectiveName(OMPD_declare_reduction);
368 while (Tok.isNot(tok::annot_pragma_openmp_end))
369 ConsumeAnyToken();
370 }
371 // Skip the last annot_pragma_openmp_end.
372 ConsumeToken();
373 return Res;
374 }
375 break;
Alexey Bataeva769e072013-03-22 06:34:35 +0000376 case OMPD_unknown:
377 Diag(Tok, diag::err_omp_unknown_directive);
378 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000379 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000380 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000381 case OMPD_task:
Alexey Bataev68446b72014-07-18 07:47:19 +0000382 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000383 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000384 case OMPD_taskwait:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000385 case OMPD_taskgroup:
Alexey Bataev6125da92014-07-21 11:26:11 +0000386 case OMPD_flush:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000387 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000388 case OMPD_for_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000389 case OMPD_sections:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000390 case OMPD_section:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000391 case OMPD_single:
Alexander Musman80c22892014-07-17 08:54:58 +0000392 case OMPD_master:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000393 case OMPD_ordered:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000394 case OMPD_critical:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000395 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000396 case OMPD_parallel_for_simd:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000397 case OMPD_parallel_sections:
Alexey Bataev0162e452014-07-22 10:10:35 +0000398 case OMPD_atomic:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000399 case OMPD_target:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000400 case OMPD_teams:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000401 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000402 case OMPD_cancel:
Samuel Antao5b0688e2015-07-22 16:02:46 +0000403 case OMPD_target_data:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000404 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000405 case OMPD_target_exit_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000406 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000407 case OMPD_target_parallel_for:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000408 case OMPD_taskloop:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000409 case OMPD_taskloop_simd:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000410 case OMPD_distribute:
Alexey Bataeva769e072013-03-22 06:34:35 +0000411 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000412 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +0000413 break;
414 }
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000415 while (Tok.isNot(tok::annot_pragma_openmp_end))
416 ConsumeAnyToken();
417 ConsumeAnyToken();
David Blaikie0403cb12016-01-15 23:43:25 +0000418 return nullptr;
Alexey Bataeva769e072013-03-22 06:34:35 +0000419}
420
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000421/// \brief Parsing of declarative or executable OpenMP directives.
422///
423/// threadprivate-directive:
424/// annot_pragma_openmp 'threadprivate' simple-variable-list
425/// annot_pragma_openmp_end
426///
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000427/// declare-reduction-directive:
428/// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':'
429/// <type> {',' <type>} ':' <expression> ')' ['initializer' '('
430/// ('omp_priv' '=' <expression>|<function_call>) ')']
431/// annot_pragma_openmp_end
432///
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000433/// executable-directive:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000434/// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000435/// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
436/// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
Alexander Musmanf82886e2014-09-18 05:12:34 +0000437/// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
Michael Wong65f367f2015-07-21 13:44:28 +0000438/// 'for simd' | 'parallel for simd' | 'target' | 'target data' |
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000439/// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' |
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000440/// 'distribute' | 'target enter data' | 'target exit data' |
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000441/// 'target parallel' | 'target parallel for' {clause}
Samuel Antao72590762016-01-19 20:04:50 +0000442/// annot_pragma_openmp_end
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000443///
Alexey Bataevc4fad652016-01-13 11:18:54 +0000444StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
445 AllowedContsructsKind Allowed) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000446 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +0000447 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000448 SmallVector<Expr *, 5> Identifiers;
449 SmallVector<OMPClause *, 5> Clauses;
Alexey Bataev4ca40ed2014-05-12 04:23:46 +0000450 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
Alexey Bataeva55ed262014-05-28 06:15:33 +0000451 FirstClauses(OMPC_unknown + 1);
Alexander Musmana8e9d2e2014-06-03 10:16:47 +0000452 unsigned ScopeFlags =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000453 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000454 SourceLocation Loc = ConsumeToken(), EndLoc;
Alexey Bataev4acb8592014-07-07 13:01:15 +0000455 auto DKind = ParseOpenMPDirectiveKind(*this);
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000456 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
Alexey Bataev758e55e2013-09-06 18:03:48 +0000457 // Name of critical directive.
458 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000459 StmtResult Directive = StmtError();
Alexey Bataev68446b72014-07-18 07:47:19 +0000460 bool HasAssociatedStatement = true;
Alexey Bataev6125da92014-07-21 11:26:11 +0000461 bool FlushHasClause = false;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000462
463 switch (DKind) {
464 case OMPD_threadprivate:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000465 if (Allowed != ACK_Any) {
466 Diag(Tok, diag::err_omp_immediate_directive)
467 << getOpenMPDirectiveName(DKind) << 0;
468 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000469 ConsumeToken();
470 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
471 // The last seen token is annot_pragma_openmp_end - need to check for
472 // extra tokens.
473 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
474 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000475 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000476 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000477 }
478 DeclGroupPtrTy Res =
Alexey Bataeva55ed262014-05-28 06:15:33 +0000479 Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000480 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
481 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000482 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000483 break;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000484 case OMPD_declare_reduction:
485 ConsumeToken();
486 if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) {
487 // The last seen token is annot_pragma_openmp_end - need to check for
488 // extra tokens.
489 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
490 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
491 << getOpenMPDirectiveName(OMPD_declare_reduction);
492 while (Tok.isNot(tok::annot_pragma_openmp_end))
493 ConsumeAnyToken();
494 }
495 ConsumeAnyToken();
496 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
497 } else
498 SkipUntil(tok::annot_pragma_openmp_end);
499 break;
Alexey Bataev6125da92014-07-21 11:26:11 +0000500 case OMPD_flush:
501 if (PP.LookAhead(0).is(tok::l_paren)) {
502 FlushHasClause = true;
503 // Push copy of the current token back to stream to properly parse
504 // pseudo-clause OMPFlushClause.
505 PP.EnterToken(Tok);
506 }
Alexey Bataev68446b72014-07-18 07:47:19 +0000507 case OMPD_taskyield:
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000508 case OMPD_barrier:
Alexey Bataev2df347a2014-07-18 10:17:07 +0000509 case OMPD_taskwait:
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000510 case OMPD_cancellation_point:
Alexey Bataev80909872015-07-02 11:25:17 +0000511 case OMPD_cancel:
Samuel Antaodf67fc42016-01-19 19:15:56 +0000512 case OMPD_target_enter_data:
Samuel Antao72590762016-01-19 20:04:50 +0000513 case OMPD_target_exit_data:
Alexey Bataevc4fad652016-01-13 11:18:54 +0000514 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataev68446b72014-07-18 07:47:19 +0000515 Diag(Tok, diag::err_omp_immediate_directive)
Alexey Bataeveb482352015-12-18 05:05:56 +0000516 << getOpenMPDirectiveName(DKind) << 0;
Alexey Bataev68446b72014-07-18 07:47:19 +0000517 }
518 HasAssociatedStatement = false;
Alexey Bataev6125da92014-07-21 11:26:11 +0000519 // Fall through for further analysis.
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000520 case OMPD_parallel:
Alexey Bataevf29276e2014-06-18 04:14:57 +0000521 case OMPD_simd:
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000522 case OMPD_for:
Alexander Musmanf82886e2014-09-18 05:12:34 +0000523 case OMPD_for_simd:
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000524 case OMPD_sections:
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000525 case OMPD_single:
Alexey Bataev4acb8592014-07-07 13:01:15 +0000526 case OMPD_section:
Alexander Musman80c22892014-07-17 08:54:58 +0000527 case OMPD_master:
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000528 case OMPD_critical:
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000529 case OMPD_parallel_for:
Alexander Musmane4e893b2014-09-23 09:33:00 +0000530 case OMPD_parallel_for_simd:
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000531 case OMPD_parallel_sections:
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000532 case OMPD_task:
Alexey Bataev0162e452014-07-22 10:10:35 +0000533 case OMPD_ordered:
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000534 case OMPD_atomic:
Alexey Bataev13314bf2014-10-09 04:18:56 +0000535 case OMPD_target:
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000536 case OMPD_teams:
Michael Wong65f367f2015-07-21 13:44:28 +0000537 case OMPD_taskgroup:
Alexey Bataev49f6e782015-12-01 04:18:41 +0000538 case OMPD_target_data:
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000539 case OMPD_target_parallel:
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000540 case OMPD_target_parallel_for:
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000541 case OMPD_taskloop:
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000542 case OMPD_taskloop_simd:
543 case OMPD_distribute: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000544 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000545 // Parse directive name of the 'critical' directive if any.
546 if (DKind == OMPD_critical) {
547 BalancedDelimiterTracker T(*this, tok::l_paren,
548 tok::annot_pragma_openmp_end);
549 if (!T.consumeOpen()) {
550 if (Tok.isAnyIdentifier()) {
551 DirName =
552 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
553 ConsumeAnyToken();
554 } else {
555 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
556 }
557 T.consumeClose();
558 }
Alexey Bataev80909872015-07-02 11:25:17 +0000559 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000560 CancelRegion = ParseOpenMPDirectiveKind(*this);
561 if (Tok.isNot(tok::annot_pragma_openmp_end))
562 ConsumeToken();
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000563 }
Alexey Bataev758e55e2013-09-06 18:03:48 +0000564
Alexey Bataevf29276e2014-06-18 04:14:57 +0000565 if (isOpenMPLoopDirective(DKind))
566 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
567 if (isOpenMPSimdDirective(DKind))
568 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
569 ParseScope OMPDirectiveScope(this, ScopeFlags);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000570 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000571
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000572 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataev6125da92014-07-21 11:26:11 +0000573 OpenMPClauseKind CKind =
574 Tok.isAnnotation()
575 ? OMPC_unknown
576 : FlushHasClause ? OMPC_flush
577 : getOpenMPClauseKind(PP.getSpelling(Tok));
Alexey Bataevaac108a2015-06-23 04:51:00 +0000578 Actions.StartOpenMPClause(CKind);
Alexey Bataev6125da92014-07-21 11:26:11 +0000579 FlushHasClause = false;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000580 OMPClause *Clause =
581 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000582 FirstClauses[CKind].setInt(true);
583 if (Clause) {
584 FirstClauses[CKind].setPointer(Clause);
585 Clauses.push_back(Clause);
586 }
587
588 // Skip ',' if any.
589 if (Tok.is(tok::comma))
590 ConsumeToken();
Alexey Bataevaac108a2015-06-23 04:51:00 +0000591 Actions.EndOpenMPClause();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000592 }
593 // End location of the directive.
594 EndLoc = Tok.getLocation();
595 // Consume final annot_pragma_openmp_end.
596 ConsumeToken();
597
Alexey Bataeveb482352015-12-18 05:05:56 +0000598 // OpenMP [2.13.8, ordered Construct, Syntax]
599 // If the depend clause is specified, the ordered construct is a stand-alone
600 // directive.
601 if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
Alexey Bataevc4fad652016-01-13 11:18:54 +0000602 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
Alexey Bataeveb482352015-12-18 05:05:56 +0000603 Diag(Loc, diag::err_omp_immediate_directive)
604 << getOpenMPDirectiveName(DKind) << 1
605 << getOpenMPClauseName(OMPC_depend);
606 }
607 HasAssociatedStatement = false;
608 }
609
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000610 StmtResult AssociatedStmt;
Alexey Bataev68446b72014-07-18 07:47:19 +0000611 if (HasAssociatedStatement) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000612 // The body is a block scope like in Lambdas and Blocks.
613 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataevbae9a792014-06-27 10:37:06 +0000614 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000615 Actions.ActOnStartOfCompoundStmt();
616 // Parse statement
617 AssociatedStmt = ParseStatement();
618 Actions.ActOnFinishOfCompoundStmt();
Alexey Bataeva8d4a5432015-04-02 07:48:16 +0000619 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000620 }
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000621 Directive = Actions.ActOnOpenMPExecutableDirective(
622 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
623 EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000624
625 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +0000626 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000627 OMPDirectiveScope.Exit();
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000628 break;
Alexey Bataeva55ed262014-05-28 06:15:33 +0000629 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000630 case OMPD_unknown:
631 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +0000632 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000633 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000634 }
635 return Directive;
636}
637
Alexey Bataeva769e072013-03-22 06:34:35 +0000638/// \brief Parses list of simple variables for '#pragma omp threadprivate'
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000639/// directive.
Alexey Bataeva769e072013-03-22 06:34:35 +0000640///
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000641/// simple-variable-list:
642/// '(' id-expression {, id-expression} ')'
643///
644bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
645 SmallVectorImpl<Expr *> &VarList,
646 bool AllowScopeSpecifier) {
647 VarList.clear();
Alexey Bataeva769e072013-03-22 06:34:35 +0000648 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000649 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000650 if (T.expectAndConsume(diag::err_expected_lparen_after,
651 getOpenMPDirectiveName(Kind)))
652 return true;
653 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000654 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +0000655
656 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000657 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000658 CXXScopeSpec SS;
659 SourceLocation TemplateKWLoc;
660 UnqualifiedId Name;
661 // Read var name.
662 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000663 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +0000664
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000665 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
David Blaikieefdccaa2016-01-15 23:43:34 +0000666 ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000667 IsCorrect = false;
668 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000669 StopBeforeMatch);
David Blaikieefdccaa2016-01-15 23:43:34 +0000670 } else if (ParseUnqualifiedId(SS, false, false, false, nullptr,
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000671 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000672 IsCorrect = false;
673 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000674 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000675 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
676 Tok.isNot(tok::annot_pragma_openmp_end)) {
677 IsCorrect = false;
678 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000679 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +0000680 Diag(PrevTok.getLocation(), diag::err_expected)
681 << tok::identifier
682 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +0000683 } else {
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000684 DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
Alexey Bataeva55ed262014-05-28 06:15:33 +0000685 ExprResult Res =
686 Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000687 if (Res.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000688 VarList.push_back(Res.get());
Alexey Bataeva769e072013-03-22 06:34:35 +0000689 }
690 // Consume ','.
691 if (Tok.is(tok::comma)) {
692 ConsumeToken();
693 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000694 }
695
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000696 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +0000697 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000698 IsCorrect = false;
699 }
700
701 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000702 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000703
704 return !IsCorrect && VarList.empty();
Alexey Bataeva769e072013-03-22 06:34:35 +0000705}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000706
707/// \brief Parsing of OpenMP clauses.
708///
709/// clause:
Alexey Bataev3778b602014-07-17 07:32:53 +0000710/// if-clause | final-clause | num_threads-clause | safelen-clause |
711/// default-clause | private-clause | firstprivate-clause | shared-clause
712/// | linear-clause | aligned-clause | collapse-clause |
713/// lastprivate-clause | reduction-clause | proc_bind-clause |
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000714/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
Alexey Bataev67a4f222014-07-23 10:25:33 +0000715/// mergeable-clause | flush-clause | read-clause | write-clause |
Alexey Bataev66b15b52015-08-21 11:14:16 +0000716/// update-clause | capture-clause | seq_cst-clause | device-clause |
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000717/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000718/// thread_limit-clause | priority-clause | grainsize-clause |
Alexey Bataev28c75412015-12-15 08:19:24 +0000719/// nogroup-clause | num_tasks-clause | hint-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000720///
721OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
722 OpenMPClauseKind CKind, bool FirstClause) {
Craig Topper161e4db2014-05-21 06:02:52 +0000723 OMPClause *Clause = nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000724 bool ErrorFound = false;
725 // Check if clause is allowed for the given directive.
726 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
Alexey Bataeva55ed262014-05-28 06:15:33 +0000727 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
728 << getOpenMPDirectiveName(DKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000729 ErrorFound = true;
730 }
731
732 switch (CKind) {
Alexey Bataev3778b602014-07-17 07:32:53 +0000733 case OMPC_final:
Alexey Bataev568a8332014-03-06 06:15:19 +0000734 case OMPC_num_threads:
Alexey Bataev62c87d22014-03-21 04:51:18 +0000735 case OMPC_safelen:
Alexey Bataev66b15b52015-08-21 11:14:16 +0000736 case OMPC_simdlen:
Alexander Musman8bd31e62014-05-27 15:12:19 +0000737 case OMPC_collapse:
Alexey Bataev10e775f2015-07-30 11:36:16 +0000738 case OMPC_ordered:
Michael Wonge710d542015-08-07 16:16:36 +0000739 case OMPC_device:
Kelvin Li099bb8c2015-11-24 20:50:12 +0000740 case OMPC_num_teams:
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000741 case OMPC_thread_limit:
Alexey Bataeva0569352015-12-01 10:17:31 +0000742 case OMPC_priority:
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000743 case OMPC_grainsize:
Alexey Bataev382967a2015-12-08 12:06:20 +0000744 case OMPC_num_tasks:
Alexey Bataev28c75412015-12-15 08:19:24 +0000745 case OMPC_hint:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000746 // OpenMP [2.5, Restrictions]
Alexey Bataev568a8332014-03-06 06:15:19 +0000747 // At most one num_threads clause can appear on the directive.
Alexey Bataev62c87d22014-03-21 04:51:18 +0000748 // OpenMP [2.8.1, simd construct, Restrictions]
Alexander Musman8bd31e62014-05-27 15:12:19 +0000749 // Only one safelen clause can appear on a simd directive.
Alexey Bataev66b15b52015-08-21 11:14:16 +0000750 // Only one simdlen clause can appear on a simd directive.
Alexander Musman8bd31e62014-05-27 15:12:19 +0000751 // Only one collapse clause can appear on a simd directive.
Michael Wonge710d542015-08-07 16:16:36 +0000752 // OpenMP [2.9.1, target data construct, Restrictions]
753 // At most one device clause can appear on the directive.
Alexey Bataev3778b602014-07-17 07:32:53 +0000754 // OpenMP [2.11.1, task Construct, Restrictions]
755 // At most one if clause can appear on the directive.
756 // At most one final clause can appear on the directive.
Kelvin Li099bb8c2015-11-24 20:50:12 +0000757 // OpenMP [teams Construct, Restrictions]
758 // At most one num_teams clause can appear on the directive.
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000759 // At most one thread_limit clause can appear on the directive.
Alexey Bataeva0569352015-12-01 10:17:31 +0000760 // OpenMP [2.9.1, task Construct, Restrictions]
761 // At most one priority clause can appear on the directive.
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000762 // OpenMP [2.9.2, taskloop Construct, Restrictions]
763 // At most one grainsize clause can appear on the directive.
Alexey Bataev382967a2015-12-08 12:06:20 +0000764 // OpenMP [2.9.2, taskloop Construct, Restrictions]
765 // At most one num_tasks clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000766 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000767 Diag(Tok, diag::err_omp_more_one_clause)
768 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000769 ErrorFound = true;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000770 }
771
Alexey Bataev10e775f2015-07-30 11:36:16 +0000772 if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren))
773 Clause = ParseOpenMPClause(CKind);
774 else
775 Clause = ParseOpenMPSingleExprClause(CKind);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000776 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000777 case OMPC_default:
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000778 case OMPC_proc_bind:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000779 // OpenMP [2.14.3.1, Restrictions]
780 // Only a single default clause may be specified on a parallel, task or
781 // teams directive.
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000782 // OpenMP [2.5, parallel Construct, Restrictions]
783 // At most one proc_bind clause can appear on the directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000784 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000785 Diag(Tok, diag::err_omp_more_one_clause)
786 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000787 ErrorFound = true;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000788 }
789
790 Clause = ParseOpenMPSimpleClause(CKind);
791 break;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000792 case OMPC_schedule:
Carlo Bertollib4adf552016-01-15 18:50:31 +0000793 case OMPC_dist_schedule:
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000794 case OMPC_defaultmap:
Alexey Bataev56dafe82014-06-20 07:16:17 +0000795 // OpenMP [2.7.1, Restrictions, p. 3]
796 // Only one schedule clause can appear on a loop directive.
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000797 // OpenMP [2.10.4, Restrictions, p. 106]
798 // At most one defaultmap clause can appear on the directive.
Alexey Bataev56dafe82014-06-20 07:16:17 +0000799 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000800 Diag(Tok, diag::err_omp_more_one_clause)
801 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000802 ErrorFound = true;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000803 }
804
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000805 case OMPC_if:
Alexey Bataev56dafe82014-06-20 07:16:17 +0000806 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
807 break;
Alexey Bataev236070f2014-06-20 11:19:47 +0000808 case OMPC_nowait:
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000809 case OMPC_untied:
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000810 case OMPC_mergeable:
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000811 case OMPC_read:
Alexey Bataevdea47612014-07-23 07:46:59 +0000812 case OMPC_write:
Alexey Bataev67a4f222014-07-23 10:25:33 +0000813 case OMPC_update:
Alexey Bataev459dec02014-07-24 06:46:57 +0000814 case OMPC_capture:
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000815 case OMPC_seq_cst:
Alexey Bataev346265e2015-09-25 10:37:12 +0000816 case OMPC_threads:
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000817 case OMPC_simd:
Alexey Bataevb825de12015-12-07 10:51:44 +0000818 case OMPC_nogroup:
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000819 // OpenMP [2.7.1, Restrictions, p. 9]
820 // Only one ordered clause can appear on a loop directive.
Alexey Bataev236070f2014-06-20 11:19:47 +0000821 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
822 // Only one nowait clause can appear on a for directive.
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000823 if (!FirstClause) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000824 Diag(Tok, diag::err_omp_more_one_clause)
825 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
Alexey Bataevdea47612014-07-23 07:46:59 +0000826 ErrorFound = true;
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000827 }
828
829 Clause = ParseOpenMPClause(CKind);
830 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000831 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000832 case OMPC_firstprivate:
Alexander Musman1bb328c2014-06-04 13:06:39 +0000833 case OMPC_lastprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000834 case OMPC_shared:
Alexey Bataevc5e02582014-06-16 07:08:35 +0000835 case OMPC_reduction:
Alexander Musman8dba6642014-04-22 13:09:42 +0000836 case OMPC_linear:
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000837 case OMPC_aligned:
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000838 case OMPC_copyin:
Alexey Bataevbae9a792014-06-27 10:37:06 +0000839 case OMPC_copyprivate:
Alexey Bataev6125da92014-07-21 11:26:11 +0000840 case OMPC_flush:
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000841 case OMPC_depend:
Kelvin Li0bff7af2015-11-23 05:32:03 +0000842 case OMPC_map:
Alexey Bataeveb482352015-12-18 05:05:56 +0000843 Clause = ParseOpenMPVarListClause(DKind, CKind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000844 break;
845 case OMPC_unknown:
846 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
Alexey Bataeva55ed262014-05-28 06:15:33 +0000847 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000848 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000849 break;
850 case OMPC_threadprivate:
Alexey Bataeva55ed262014-05-28 06:15:33 +0000851 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
852 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000853 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000854 break;
855 }
Craig Topper161e4db2014-05-21 06:02:52 +0000856 return ErrorFound ? nullptr : Clause;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000857}
858
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000859/// \brief Parsing of OpenMP clauses with single expressions like 'final',
Alexey Bataeva0569352015-12-01 10:17:31 +0000860/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
Alexey Bataev28c75412015-12-15 08:19:24 +0000861/// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000862///
Alexey Bataev3778b602014-07-17 07:32:53 +0000863/// final-clause:
864/// 'final' '(' expression ')'
865///
Alexey Bataev62c87d22014-03-21 04:51:18 +0000866/// num_threads-clause:
867/// 'num_threads' '(' expression ')'
868///
869/// safelen-clause:
870/// 'safelen' '(' expression ')'
871///
Alexey Bataev66b15b52015-08-21 11:14:16 +0000872/// simdlen-clause:
873/// 'simdlen' '(' expression ')'
874///
Alexander Musman8bd31e62014-05-27 15:12:19 +0000875/// collapse-clause:
876/// 'collapse' '(' expression ')'
877///
Alexey Bataeva0569352015-12-01 10:17:31 +0000878/// priority-clause:
879/// 'priority' '(' expression ')'
880///
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000881/// grainsize-clause:
882/// 'grainsize' '(' expression ')'
883///
Alexey Bataev382967a2015-12-08 12:06:20 +0000884/// num_tasks-clause:
885/// 'num_tasks' '(' expression ')'
886///
Alexey Bataev28c75412015-12-15 08:19:24 +0000887/// hint-clause:
888/// 'hint' '(' expression ')'
889///
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000890OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
891 SourceLocation Loc = ConsumeToken();
892
893 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
894 if (T.expectAndConsume(diag::err_expected_lparen_after,
895 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000896 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000897
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000898 SourceLocation ELoc = Tok.getLocation();
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000899 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
900 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000901 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000902
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000903 // Parse ')'.
904 T.consumeClose();
905
906 if (Val.isInvalid())
Craig Topper161e4db2014-05-21 06:02:52 +0000907 return nullptr;
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000908
Alexey Bataeva55ed262014-05-28 06:15:33 +0000909 return Actions.ActOnOpenMPSingleExprClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000910 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000911}
912
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000913/// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000914///
915/// default-clause:
916/// 'default' '(' 'none' | 'shared' ')
917///
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000918/// proc_bind-clause:
919/// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
920///
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000921OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
922 SourceLocation Loc = Tok.getLocation();
923 SourceLocation LOpen = ConsumeToken();
924 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000925 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000926 if (T.expectAndConsume(diag::err_expected_lparen_after,
927 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +0000928 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000929
Alexey Bataeva55ed262014-05-28 06:15:33 +0000930 unsigned Type = getOpenMPSimpleClauseType(
931 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000932 SourceLocation TypeLoc = Tok.getLocation();
933 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
934 Tok.isNot(tok::annot_pragma_openmp_end))
935 ConsumeAnyToken();
936
937 // Parse ')'.
938 T.consumeClose();
939
940 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
941 Tok.getLocation());
942}
943
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000944/// \brief Parsing of OpenMP clauses like 'ordered'.
945///
946/// ordered-clause:
947/// 'ordered'
948///
Alexey Bataev236070f2014-06-20 11:19:47 +0000949/// nowait-clause:
950/// 'nowait'
951///
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000952/// untied-clause:
953/// 'untied'
954///
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000955/// mergeable-clause:
956/// 'mergeable'
957///
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000958/// read-clause:
959/// 'read'
960///
Alexey Bataev346265e2015-09-25 10:37:12 +0000961/// threads-clause:
962/// 'threads'
963///
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000964/// simd-clause:
965/// 'simd'
966///
Alexey Bataevb825de12015-12-07 10:51:44 +0000967/// nogroup-clause:
968/// 'nogroup'
969///
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000970OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
971 SourceLocation Loc = Tok.getLocation();
972 ConsumeAnyToken();
973
974 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
975}
976
977
Alexey Bataev56dafe82014-06-20 07:16:17 +0000978/// \brief Parsing of OpenMP clauses with single expressions and some additional
979/// argument like 'schedule' or 'dist_schedule'.
980///
981/// schedule-clause:
Alexey Bataev6402bca2015-12-28 07:25:51 +0000982/// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ]
983/// ')'
Alexey Bataev56dafe82014-06-20 07:16:17 +0000984///
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000985/// if-clause:
986/// 'if' '(' [ directive-name-modifier ':' ] expression ')'
987///
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000988/// defaultmap:
989/// 'defaultmap' '(' modifier ':' kind ')'
990///
Alexey Bataev56dafe82014-06-20 07:16:17 +0000991OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
992 SourceLocation Loc = ConsumeToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +0000993 SourceLocation DelimLoc;
Alexey Bataev56dafe82014-06-20 07:16:17 +0000994 // Parse '('.
995 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
996 if (T.expectAndConsume(diag::err_expected_lparen_after,
997 getOpenMPClauseName(Kind)))
998 return nullptr;
999
1000 ExprResult Val;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001001 SmallVector<unsigned, 4> Arg;
1002 SmallVector<SourceLocation, 4> KLoc;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001003 if (Kind == OMPC_schedule) {
Alexey Bataev6402bca2015-12-28 07:25:51 +00001004 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
1005 Arg.resize(NumberOfElements);
1006 KLoc.resize(NumberOfElements);
1007 Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown;
1008 Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown;
1009 Arg[ScheduleKind] = OMPC_SCHEDULE_unknown;
1010 auto KindModifier = getOpenMPSimpleClauseType(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001011 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
Alexey Bataev6402bca2015-12-28 07:25:51 +00001012 if (KindModifier > OMPC_SCHEDULE_unknown) {
1013 // Parse 'modifier'
1014 Arg[Modifier1] = KindModifier;
1015 KLoc[Modifier1] = Tok.getLocation();
1016 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1017 Tok.isNot(tok::annot_pragma_openmp_end))
1018 ConsumeAnyToken();
1019 if (Tok.is(tok::comma)) {
1020 // Parse ',' 'modifier'
1021 ConsumeAnyToken();
1022 KindModifier = getOpenMPSimpleClauseType(
1023 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1024 Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown
1025 ? KindModifier
Aaron Ballmanad8a1042015-12-28 15:52:46 +00001026 : (unsigned)OMPC_SCHEDULE_unknown;
Alexey Bataev6402bca2015-12-28 07:25:51 +00001027 KLoc[Modifier2] = Tok.getLocation();
1028 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1029 Tok.isNot(tok::annot_pragma_openmp_end))
1030 ConsumeAnyToken();
1031 }
1032 // Parse ':'
1033 if (Tok.is(tok::colon))
1034 ConsumeAnyToken();
1035 else
1036 Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier";
1037 KindModifier = getOpenMPSimpleClauseType(
1038 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
1039 }
1040 Arg[ScheduleKind] = KindModifier;
1041 KLoc[ScheduleKind] = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001042 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1043 Tok.isNot(tok::annot_pragma_openmp_end))
1044 ConsumeAnyToken();
Alexey Bataev6402bca2015-12-28 07:25:51 +00001045 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
1046 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
1047 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001048 Tok.is(tok::comma))
1049 DelimLoc = ConsumeAnyToken();
Carlo Bertollib4adf552016-01-15 18:50:31 +00001050 } else if (Kind == OMPC_dist_schedule) {
1051 Arg.push_back(getOpenMPSimpleClauseType(
1052 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1053 KLoc.push_back(Tok.getLocation());
1054 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1055 Tok.isNot(tok::annot_pragma_openmp_end))
1056 ConsumeAnyToken();
1057 if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
1058 DelimLoc = ConsumeAnyToken();
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001059 } else if (Kind == OMPC_defaultmap) {
1060 // Get a defaultmap modifier
1061 Arg.push_back(getOpenMPSimpleClauseType(
1062 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1063 KLoc.push_back(Tok.getLocation());
1064 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1065 Tok.isNot(tok::annot_pragma_openmp_end))
1066 ConsumeAnyToken();
1067 // Parse ':'
1068 if (Tok.is(tok::colon))
1069 ConsumeAnyToken();
1070 else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown)
1071 Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier";
1072 // Get a defaultmap kind
1073 Arg.push_back(getOpenMPSimpleClauseType(
1074 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)));
1075 KLoc.push_back(Tok.getLocation());
1076 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
1077 Tok.isNot(tok::annot_pragma_openmp_end))
1078 ConsumeAnyToken();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001079 } else {
1080 assert(Kind == OMPC_if);
Alexey Bataev6402bca2015-12-28 07:25:51 +00001081 KLoc.push_back(Tok.getLocation());
1082 Arg.push_back(ParseOpenMPDirectiveKind(*this));
1083 if (Arg.back() != OMPD_unknown) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001084 ConsumeToken();
1085 if (Tok.is(tok::colon))
1086 DelimLoc = ConsumeToken();
1087 else
1088 Diag(Tok, diag::warn_pragma_expected_colon)
1089 << "directive name modifier";
1090 }
1091 }
Alexey Bataev56dafe82014-06-20 07:16:17 +00001092
Carlo Bertollib4adf552016-01-15 18:50:31 +00001093 bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) ||
1094 (Kind == OMPC_dist_schedule && DelimLoc.isValid()) ||
1095 Kind == OMPC_if;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001096 if (NeedAnExpression) {
1097 SourceLocation ELoc = Tok.getLocation();
Alexey Bataev56dafe82014-06-20 07:16:17 +00001098 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
1099 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001100 Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc);
Alexey Bataev56dafe82014-06-20 07:16:17 +00001101 }
1102
1103 // Parse ')'.
1104 T.consumeClose();
1105
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001106 if (NeedAnExpression && Val.isInvalid())
1107 return nullptr;
1108
Alexey Bataev56dafe82014-06-20 07:16:17 +00001109 return Actions.ActOnOpenMPSingleExprWithArgClause(
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001110 Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc,
Alexey Bataev56dafe82014-06-20 07:16:17 +00001111 T.getCloseLocation());
1112}
1113
Alexey Bataevc5e02582014-06-16 07:08:35 +00001114static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
1115 UnqualifiedId &ReductionId) {
1116 SourceLocation TemplateKWLoc;
1117 if (ReductionIdScopeSpec.isEmpty()) {
1118 auto OOK = OO_None;
1119 switch (P.getCurToken().getKind()) {
1120 case tok::plus:
1121 OOK = OO_Plus;
1122 break;
1123 case tok::minus:
1124 OOK = OO_Minus;
1125 break;
1126 case tok::star:
1127 OOK = OO_Star;
1128 break;
1129 case tok::amp:
1130 OOK = OO_Amp;
1131 break;
1132 case tok::pipe:
1133 OOK = OO_Pipe;
1134 break;
1135 case tok::caret:
1136 OOK = OO_Caret;
1137 break;
1138 case tok::ampamp:
1139 OOK = OO_AmpAmp;
1140 break;
1141 case tok::pipepipe:
1142 OOK = OO_PipePipe;
1143 break;
1144 default:
1145 break;
1146 }
1147 if (OOK != OO_None) {
1148 SourceLocation OpLoc = P.ConsumeToken();
Alexey Bataev23b69422014-06-18 07:08:49 +00001149 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
Alexey Bataevc5e02582014-06-16 07:08:35 +00001150 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
1151 return false;
1152 }
1153 }
1154 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
1155 /*AllowDestructorName*/ false,
David Blaikieefdccaa2016-01-15 23:43:34 +00001156 /*AllowConstructorName*/ false, nullptr,
Alexey Bataevc5e02582014-06-16 07:08:35 +00001157 TemplateKWLoc, ReductionId);
1158}
1159
Alexander Musman1bb328c2014-06-04 13:06:39 +00001160/// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
Alexey Bataev6125da92014-07-21 11:26:11 +00001161/// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001162///
1163/// private-clause:
1164/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001165/// firstprivate-clause:
1166/// 'firstprivate' '(' list ')'
Alexander Musman1bb328c2014-06-04 13:06:39 +00001167/// lastprivate-clause:
1168/// 'lastprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +00001169/// shared-clause:
1170/// 'shared' '(' list ')'
Alexander Musman8dba6642014-04-22 13:09:42 +00001171/// linear-clause:
Alexey Bataev182227b2015-08-20 10:54:39 +00001172/// 'linear' '(' linear-list [ ':' linear-step ] ')'
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001173/// aligned-clause:
1174/// 'aligned' '(' list [ ':' alignment ] ')'
Alexey Bataevc5e02582014-06-16 07:08:35 +00001175/// reduction-clause:
1176/// 'reduction' '(' reduction-identifier ':' list ')'
Alexey Bataev6125da92014-07-21 11:26:11 +00001177/// copyprivate-clause:
1178/// 'copyprivate' '(' list ')'
1179/// flush-clause:
1180/// 'flush' '(' list ')'
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001181/// depend-clause:
Alexey Bataeveb482352015-12-18 05:05:56 +00001182/// 'depend' '(' in | out | inout : list | source ')'
Kelvin Li0bff7af2015-11-23 05:32:03 +00001183/// map-clause:
1184/// 'map' '(' [ [ always , ]
1185/// to | from | tofrom | alloc | release | delete ':' ] list ')';
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001186///
Alexey Bataev182227b2015-08-20 10:54:39 +00001187/// For 'linear' clause linear-list may have the following forms:
1188/// list
1189/// modifier(list)
1190/// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++).
Alexey Bataeveb482352015-12-18 05:05:56 +00001191OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind,
1192 OpenMPClauseKind Kind) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001193 SourceLocation Loc = Tok.getLocation();
1194 SourceLocation LOpen = ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +00001195 SourceLocation ColonLoc = SourceLocation();
Alexey Bataevc5e02582014-06-16 07:08:35 +00001196 // Optional scope specifier and unqualified id for reduction identifier.
1197 CXXScopeSpec ReductionIdScopeSpec;
1198 UnqualifiedId ReductionId;
1199 bool InvalidReductionId = false;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001200 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
Alexey Bataev182227b2015-08-20 10:54:39 +00001201 // OpenMP 4.1 [2.15.3.7, linear Clause]
1202 // If no modifier is specified it is assumed to be val.
1203 OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001204 OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
1205 OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown;
Samuel Antao23abd722016-01-19 20:40:49 +00001206 bool MapTypeIsImplicit = false;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001207 bool MapTypeModifierSpecified = false;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001208 SourceLocation DepLinMapLoc;
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001209
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001210 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +00001211 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001212 if (T.expectAndConsume(diag::err_expected_lparen_after,
1213 getOpenMPClauseName(Kind)))
Craig Topper161e4db2014-05-21 06:02:52 +00001214 return nullptr;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001215
Alexey Bataev182227b2015-08-20 10:54:39 +00001216 bool NeedRParenForLinear = false;
1217 BalancedDelimiterTracker LinearT(*this, tok::l_paren,
1218 tok::annot_pragma_openmp_end);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001219 // Handle reduction-identifier for reduction clause.
1220 if (Kind == OMPC_reduction) {
1221 ColonProtectionRAIIObject ColonRAII(*this);
Alexey Bataeva839ddd2016-03-17 10:19:46 +00001222 if (getLangOpts().CPlusPlus)
1223 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec,
1224 /*ObjectType=*/nullptr,
1225 /*EnteringContext=*/false);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001226 InvalidReductionId =
1227 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
1228 if (InvalidReductionId) {
1229 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1230 StopBeforeMatch);
1231 }
1232 if (Tok.is(tok::colon)) {
1233 ColonLoc = ConsumeToken();
1234 } else {
1235 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
1236 }
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001237 } else if (Kind == OMPC_depend) {
1238 // Handle dependency type for depend clause.
1239 ColonProtectionRAIIObject ColonRAII(*this);
1240 DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
1241 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
Kelvin Li0bff7af2015-11-23 05:32:03 +00001242 DepLinMapLoc = Tok.getLocation();
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001243
1244 if (DepKind == OMPC_DEPEND_unknown) {
1245 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1246 StopBeforeMatch);
1247 } else {
1248 ConsumeToken();
Alexey Bataeveb482352015-12-18 05:05:56 +00001249 // Special processing for depend(source) clause.
1250 if (DKind == OMPD_ordered && DepKind == OMPC_DEPEND_source) {
1251 // Parse ')'.
1252 T.consumeClose();
1253 return Actions.ActOnOpenMPVarListClause(
1254 Kind, llvm::None, /*TailExpr=*/nullptr, Loc, LOpen,
1255 /*ColonLoc=*/SourceLocation(), Tok.getLocation(),
1256 ReductionIdScopeSpec, DeclarationNameInfo(), DepKind,
Samuel Antao23abd722016-01-19 20:40:49 +00001257 LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit,
1258 DepLinMapLoc);
Alexey Bataeveb482352015-12-18 05:05:56 +00001259 }
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001260 }
1261 if (Tok.is(tok::colon)) {
1262 ColonLoc = ConsumeToken();
1263 } else {
Alexey Bataeveb482352015-12-18 05:05:56 +00001264 Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
1265 : diag::warn_pragma_expected_colon)
1266 << "dependency type";
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001267 }
Alexey Bataev182227b2015-08-20 10:54:39 +00001268 } else if (Kind == OMPC_linear) {
1269 // Try to parse modifier if any.
1270 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
Alexey Bataev182227b2015-08-20 10:54:39 +00001271 LinearModifier = static_cast<OpenMPLinearClauseKind>(
Alexey Bataev1185e192015-08-20 12:15:57 +00001272 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)));
Kelvin Li0bff7af2015-11-23 05:32:03 +00001273 DepLinMapLoc = ConsumeToken();
Alexey Bataev182227b2015-08-20 10:54:39 +00001274 LinearT.consumeOpen();
1275 NeedRParenForLinear = true;
1276 }
Kelvin Li0bff7af2015-11-23 05:32:03 +00001277 } else if (Kind == OMPC_map) {
1278 // Handle map type for map clause.
1279 ColonProtectionRAIIObject ColonRAII(*this);
1280
Samuel Antaof91b1632016-02-27 00:01:58 +00001281 /// The map clause modifier token can be either a identifier or the C++
1282 /// delete keyword.
1283 auto IsMapClauseModifierToken = [](const Token &Tok) {
1284 return Tok.isOneOf(tok::identifier, tok::kw_delete);
1285 };
1286
1287 // The first identifier may be a list item, a map-type or a
1288 // map-type-modifier. The map modifier can also be delete which has the same
1289 // spelling of the C++ delete keyword.
Kelvin Li0bff7af2015-11-23 05:32:03 +00001290 MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
Samuel Antaof91b1632016-02-27 00:01:58 +00001291 Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : ""));
Kelvin Li0bff7af2015-11-23 05:32:03 +00001292 DepLinMapLoc = Tok.getLocation();
1293 bool ColonExpected = false;
1294
Samuel Antaof91b1632016-02-27 00:01:58 +00001295 if (IsMapClauseModifierToken(Tok)) {
Kelvin Li0bff7af2015-11-23 05:32:03 +00001296 if (PP.LookAhead(0).is(tok::colon)) {
1297 MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
Samuel Antaof91b1632016-02-27 00:01:58 +00001298 Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : ""));
Kelvin Li0bff7af2015-11-23 05:32:03 +00001299 if (MapType == OMPC_MAP_unknown) {
1300 Diag(Tok, diag::err_omp_unknown_map_type);
1301 } else if (MapType == OMPC_MAP_always) {
1302 Diag(Tok, diag::err_omp_map_type_missing);
1303 }
1304 ConsumeToken();
1305 } else if (PP.LookAhead(0).is(tok::comma)) {
Samuel Antaof91b1632016-02-27 00:01:58 +00001306 if (IsMapClauseModifierToken(PP.LookAhead(1)) &&
Kelvin Li0bff7af2015-11-23 05:32:03 +00001307 PP.LookAhead(2).is(tok::colon)) {
1308 MapTypeModifier =
1309 static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
Samuel Antaof91b1632016-02-27 00:01:58 +00001310 Kind,
1311 IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : ""));
Kelvin Li0bff7af2015-11-23 05:32:03 +00001312 if (MapTypeModifier != OMPC_MAP_always) {
1313 Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1314 MapTypeModifier = OMPC_MAP_unknown;
1315 } else {
1316 MapTypeModifierSpecified = true;
1317 }
1318
1319 ConsumeToken();
1320 ConsumeToken();
1321
1322 MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType(
Samuel Antaof91b1632016-02-27 00:01:58 +00001323 Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : ""));
Kelvin Li0bff7af2015-11-23 05:32:03 +00001324 if (MapType == OMPC_MAP_unknown || MapType == OMPC_MAP_always) {
1325 Diag(Tok, diag::err_omp_unknown_map_type);
1326 }
1327 ConsumeToken();
1328 } else {
1329 MapType = OMPC_MAP_tofrom;
Samuel Antao23abd722016-01-19 20:40:49 +00001330 MapTypeIsImplicit = true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001331 }
1332 } else {
1333 MapType = OMPC_MAP_tofrom;
Samuel Antao23abd722016-01-19 20:40:49 +00001334 MapTypeIsImplicit = true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001335 }
1336 } else {
Samuel Antao5de996e2016-01-22 20:21:36 +00001337 MapType = OMPC_MAP_tofrom;
1338 MapTypeIsImplicit = true;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001339 }
1340
1341 if (Tok.is(tok::colon)) {
1342 ColonLoc = ConsumeToken();
1343 } else if (ColonExpected) {
1344 Diag(Tok, diag::warn_pragma_expected_colon) << "map type";
1345 }
Alexey Bataevc5e02582014-06-16 07:08:35 +00001346 }
1347
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001348 SmallVector<Expr *, 5> Vars;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001349 bool IsComma =
1350 ((Kind != OMPC_reduction) && (Kind != OMPC_depend) &&
1351 (Kind != OMPC_map)) ||
1352 ((Kind == OMPC_reduction) && !InvalidReductionId) ||
Samuel Antao5de996e2016-01-22 20:21:36 +00001353 ((Kind == OMPC_map) && (MapType != OMPC_MAP_unknown) &&
Kelvin Li0bff7af2015-11-23 05:32:03 +00001354 (!MapTypeModifierSpecified ||
1355 (MapTypeModifierSpecified && MapTypeModifier == OMPC_MAP_always))) ||
1356 ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown);
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001357 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
Alexander Musman8dba6642014-04-22 13:09:42 +00001358 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001359 Tok.isNot(tok::annot_pragma_openmp_end))) {
Alexander Musman8dba6642014-04-22 13:09:42 +00001360 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001361 // Parse variable
Kaelyn Takata15867822014-11-21 18:48:04 +00001362 ExprResult VarExpr =
1363 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001364 if (VarExpr.isUsable()) {
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001365 Vars.push_back(VarExpr.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001366 } else {
1367 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +00001368 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001369 }
1370 // Skip ',' if any
1371 IsComma = Tok.is(tok::comma);
Alexander Musman8dba6642014-04-22 13:09:42 +00001372 if (IsComma)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001373 ConsumeToken();
Alexander Musman8dba6642014-04-22 13:09:42 +00001374 else if (Tok.isNot(tok::r_paren) &&
1375 Tok.isNot(tok::annot_pragma_openmp_end) &&
1376 (!MayHaveTail || Tok.isNot(tok::colon)))
Alexey Bataev6125da92014-07-21 11:26:11 +00001377 Diag(Tok, diag::err_omp_expected_punc)
1378 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
1379 : getOpenMPClauseName(Kind))
1380 << (Kind == OMPC_flush);
Alexander Musman8dba6642014-04-22 13:09:42 +00001381 }
1382
Alexey Bataev182227b2015-08-20 10:54:39 +00001383 // Parse ')' for linear clause with modifier.
1384 if (NeedRParenForLinear)
1385 LinearT.consumeClose();
1386
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001387 // Parse ':' linear-step (or ':' alignment).
Craig Topper161e4db2014-05-21 06:02:52 +00001388 Expr *TailExpr = nullptr;
Alexander Musman8dba6642014-04-22 13:09:42 +00001389 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
1390 if (MustHaveTail) {
1391 ColonLoc = Tok.getLocation();
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001392 SourceLocation ELoc = ConsumeToken();
1393 ExprResult Tail = ParseAssignmentExpression();
1394 Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001395 if (Tail.isUsable())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001396 TailExpr = Tail.get();
Alexander Musman8dba6642014-04-22 13:09:42 +00001397 else
1398 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1399 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001400 }
1401
1402 // Parse ')'.
1403 T.consumeClose();
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001404 if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) ||
Samuel Antao5de996e2016-01-22 20:21:36 +00001405 (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
1406 (MustHaveTail && !TailExpr) || InvalidReductionId) {
Craig Topper161e4db2014-05-21 06:02:52 +00001407 return nullptr;
Kelvin Li0bff7af2015-11-23 05:32:03 +00001408 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001409
Alexey Bataevc5e02582014-06-16 07:08:35 +00001410 return Actions.ActOnOpenMPVarListClause(
1411 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
1412 ReductionIdScopeSpec,
1413 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001414 : DeclarationNameInfo(),
Samuel Antao23abd722016-01-19 20:40:49 +00001415 DepKind, LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit,
1416 DepLinMapLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001417}
1418