1 //===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// \brief This file implements parsing of all OpenMP directives and clauses.
12 //===----------------------------------------------------------------------===//
14 #include "RAIIObjectsForParser.h"
15 #include "clang/AST/ASTConsumer.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/StmtOpenMP.h"
18 #include "clang/Parse/ParseDiagnostic.h"
19 #include "clang/Parse/Parser.h"
20 #include "clang/Sema/Scope.h"
21 #include "llvm/ADT/PointerIntPair.h"
22 using namespace clang;
24 //===----------------------------------------------------------------------===//
25 // OpenMP declarative directives.
26 //===----------------------------------------------------------------------===//
28 static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
29 // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
30 // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
31 // TODO: add other combined directives in topological order.
32 const OpenMPDirectiveKind F[][3] = {
33 {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
34 OMPD_cancellation_point},
35 {OMPD_for, OMPD_simd, OMPD_for_simd},
36 {OMPD_parallel, OMPD_for, OMPD_parallel_for},
37 {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
38 {OMPD_parallel, OMPD_sections, OMPD_parallel_sections}};
39 auto Tok = P.getCurToken();
43 : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
44 bool TokenMatched = false;
45 for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
46 if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
49 !P.getPreprocessor().getSpelling(Tok).compare("cancellation");
51 TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
54 Tok = P.getPreprocessor().LookAhead(0);
58 : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
59 if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
61 (i == 0) && !P.getPreprocessor().getSpelling(Tok).compare("point");
63 TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown;
74 /// \brief Parsing of declarative OpenMP directives.
76 /// threadprivate-directive:
77 /// annot_pragma_openmp 'threadprivate' simple-variable-list
79 Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
80 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
81 ParenBraceBracketBalancer BalancerRAIIObj(*this);
83 SourceLocation Loc = ConsumeToken();
84 SmallVector<Expr *, 5> Identifiers;
85 auto DKind = ParseOpenMPDirectiveKind(*this);
88 case OMPD_threadprivate:
90 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
91 // The last seen token is annot_pragma_openmp_end - need to check for
93 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
94 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
95 << getOpenMPDirectiveName(OMPD_threadprivate);
96 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
98 // Skip the last annot_pragma_openmp_end.
100 return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
104 Diag(Tok, diag::err_omp_unknown_directive);
122 case OMPD_parallel_for:
123 case OMPD_parallel_for_simd:
124 case OMPD_parallel_sections:
128 case OMPD_cancellation_point:
130 Diag(Tok, diag::err_omp_unexpected_directive)
131 << getOpenMPDirectiveName(DKind);
134 SkipUntil(tok::annot_pragma_openmp_end);
135 return DeclGroupPtrTy();
138 /// \brief Parsing of declarative or executable OpenMP directives.
140 /// threadprivate-directive:
141 /// annot_pragma_openmp 'threadprivate' simple-variable-list
142 /// annot_pragma_openmp_end
144 /// executable-directive:
145 /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' |
146 /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] |
147 /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' |
148 /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' |
149 /// 'for simd' | 'parallel for simd' | 'target' | 'teams' | 'taskgroup'
151 /// annot_pragma_openmp_end
154 Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) {
155 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
156 ParenBraceBracketBalancer BalancerRAIIObj(*this);
157 SmallVector<Expr *, 5> Identifiers;
158 SmallVector<OMPClause *, 5> Clauses;
159 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1>
160 FirstClauses(OMPC_unknown + 1);
161 unsigned ScopeFlags =
162 Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope;
163 SourceLocation Loc = ConsumeToken(), EndLoc;
164 auto DKind = ParseOpenMPDirectiveKind(*this);
165 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
166 // Name of critical directive.
167 DeclarationNameInfo DirName;
168 StmtResult Directive = StmtError();
169 bool HasAssociatedStatement = true;
170 bool FlushHasClause = false;
173 case OMPD_threadprivate:
175 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) {
176 // The last seen token is annot_pragma_openmp_end - need to check for
178 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
179 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
180 << getOpenMPDirectiveName(OMPD_threadprivate);
181 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
184 Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers);
185 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
187 SkipUntil(tok::annot_pragma_openmp_end);
190 if (PP.LookAhead(0).is(tok::l_paren)) {
191 FlushHasClause = true;
192 // Push copy of the current token back to stream to properly parse
193 // pseudo-clause OMPFlushClause.
199 case OMPD_cancellation_point:
201 if (!StandAloneAllowed) {
202 Diag(Tok, diag::err_omp_immediate_directive)
203 << getOpenMPDirectiveName(DKind);
205 HasAssociatedStatement = false;
206 // Fall through for further analysis.
216 case OMPD_parallel_for:
217 case OMPD_parallel_for_simd:
218 case OMPD_parallel_sections:
224 case OMPD_taskgroup: {
226 // Parse directive name of the 'critical' directive if any.
227 if (DKind == OMPD_critical) {
228 BalancedDelimiterTracker T(*this, tok::l_paren,
229 tok::annot_pragma_openmp_end);
230 if (!T.consumeOpen()) {
231 if (Tok.isAnyIdentifier()) {
233 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
236 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
240 } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
241 CancelRegion = ParseOpenMPDirectiveKind(*this);
242 if (Tok.isNot(tok::annot_pragma_openmp_end))
246 if (isOpenMPLoopDirective(DKind))
247 ScopeFlags |= Scope::OpenMPLoopDirectiveScope;
248 if (isOpenMPSimdDirective(DKind))
249 ScopeFlags |= Scope::OpenMPSimdDirectiveScope;
250 ParseScope OMPDirectiveScope(this, ScopeFlags);
251 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
253 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
254 OpenMPClauseKind CKind =
257 : FlushHasClause ? OMPC_flush
258 : getOpenMPClauseKind(PP.getSpelling(Tok));
259 Actions.StartOpenMPClause(CKind);
260 FlushHasClause = false;
262 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
263 FirstClauses[CKind].setInt(true);
265 FirstClauses[CKind].setPointer(Clause);
266 Clauses.push_back(Clause);
270 if (Tok.is(tok::comma))
272 Actions.EndOpenMPClause();
274 // End location of the directive.
275 EndLoc = Tok.getLocation();
276 // Consume final annot_pragma_openmp_end.
279 StmtResult AssociatedStmt;
280 bool CreateDirective = true;
281 if (HasAssociatedStatement) {
282 // The body is a block scope like in Lambdas and Blocks.
283 Sema::CompoundScopeRAII CompoundScope(Actions);
284 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
285 Actions.ActOnStartOfCompoundStmt();
287 AssociatedStmt = ParseStatement();
288 Actions.ActOnFinishOfCompoundStmt();
289 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
290 CreateDirective = AssociatedStmt.isUsable();
293 Directive = Actions.ActOnOpenMPExecutableDirective(
294 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
298 Actions.EndOpenMPDSABlock(Directive.get());
299 OMPDirectiveScope.Exit();
303 Diag(Tok, diag::err_omp_unknown_directive);
304 SkipUntil(tok::annot_pragma_openmp_end);
310 /// \brief Parses list of simple variables for '#pragma omp threadprivate'
313 /// simple-variable-list:
314 /// '(' id-expression {, id-expression} ')'
316 bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
317 SmallVectorImpl<Expr *> &VarList,
318 bool AllowScopeSpecifier) {
321 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
322 if (T.expectAndConsume(diag::err_expected_lparen_after,
323 getOpenMPDirectiveName(Kind)))
325 bool IsCorrect = true;
326 bool NoIdentIsFound = true;
328 // Read tokens while ')' or annot_pragma_openmp_end is not found.
329 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
331 SourceLocation TemplateKWLoc;
335 NoIdentIsFound = false;
337 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
338 ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
340 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
342 } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
343 TemplateKWLoc, Name)) {
345 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
347 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
348 Tok.isNot(tok::annot_pragma_openmp_end)) {
350 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
352 Diag(PrevTok.getLocation(), diag::err_expected)
354 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
356 DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
358 Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo);
360 VarList.push_back(Res.get());
363 if (Tok.is(tok::comma)) {
368 if (NoIdentIsFound) {
369 Diag(Tok, diag::err_expected) << tok::identifier;
374 IsCorrect = !T.consumeClose() && IsCorrect;
376 return !IsCorrect && VarList.empty();
379 /// \brief Parsing of OpenMP clauses.
382 /// if-clause | final-clause | num_threads-clause | safelen-clause |
383 /// default-clause | private-clause | firstprivate-clause | shared-clause
384 /// | linear-clause | aligned-clause | collapse-clause |
385 /// lastprivate-clause | reduction-clause | proc_bind-clause |
386 /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
387 /// mergeable-clause | flush-clause | read-clause | write-clause |
388 /// update-clause | capture-clause | seq_cst-clause
390 OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
391 OpenMPClauseKind CKind, bool FirstClause) {
392 OMPClause *Clause = nullptr;
393 bool ErrorFound = false;
394 // Check if clause is allowed for the given directive.
395 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
396 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
397 << getOpenMPDirectiveName(DKind);
404 case OMPC_num_threads:
407 // OpenMP [2.5, Restrictions]
408 // At most one if clause can appear on the directive.
409 // At most one num_threads clause can appear on the directive.
410 // OpenMP [2.8.1, simd construct, Restrictions]
411 // Only one safelen clause can appear on a simd directive.
412 // Only one collapse clause can appear on a simd directive.
413 // OpenMP [2.11.1, task Construct, Restrictions]
414 // At most one if clause can appear on the directive.
415 // At most one final clause can appear on the directive.
417 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
418 << getOpenMPClauseName(CKind);
422 Clause = ParseOpenMPSingleExprClause(CKind);
426 // OpenMP [2.14.3.1, Restrictions]
427 // Only a single default clause may be specified on a parallel, task or
429 // OpenMP [2.5, parallel Construct, Restrictions]
430 // At most one proc_bind clause can appear on the directive.
432 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
433 << getOpenMPClauseName(CKind);
437 Clause = ParseOpenMPSimpleClause(CKind);
440 // OpenMP [2.7.1, Restrictions, p. 3]
441 // Only one schedule clause can appear on a loop directive.
443 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
444 << getOpenMPClauseName(CKind);
448 Clause = ParseOpenMPSingleExprWithArgClause(CKind);
459 // OpenMP [2.7.1, Restrictions, p. 9]
460 // Only one ordered clause can appear on a loop directive.
461 // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
462 // Only one nowait clause can appear on a for directive.
464 Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
465 << getOpenMPClauseName(CKind);
469 Clause = ParseOpenMPClause(CKind);
472 case OMPC_firstprivate:
473 case OMPC_lastprivate:
479 case OMPC_copyprivate:
482 Clause = ParseOpenMPVarListClause(CKind);
485 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
486 << getOpenMPDirectiveName(DKind);
487 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
489 case OMPC_threadprivate:
490 Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind)
491 << getOpenMPDirectiveName(DKind);
492 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
495 return ErrorFound ? nullptr : Clause;
498 /// \brief Parsing of OpenMP clauses with single expressions like 'if',
499 /// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
503 /// 'if' '(' expression ')'
506 /// 'final' '(' expression ')'
508 /// num_threads-clause:
509 /// 'num_threads' '(' expression ')'
512 /// 'safelen' '(' expression ')'
515 /// 'collapse' '(' expression ')'
517 OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
518 SourceLocation Loc = ConsumeToken();
520 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
521 if (T.expectAndConsume(diag::err_expected_lparen_after,
522 getOpenMPClauseName(Kind)))
525 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
526 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
534 return Actions.ActOnOpenMPSingleExprClause(
535 Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation());
538 /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'.
541 /// 'default' '(' 'none' | 'shared' ')
543 /// proc_bind-clause:
544 /// 'proc_bind' '(' 'master' | 'close' | 'spread' ')
546 OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
547 SourceLocation Loc = Tok.getLocation();
548 SourceLocation LOpen = ConsumeToken();
550 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
551 if (T.expectAndConsume(diag::err_expected_lparen_after,
552 getOpenMPClauseName(Kind)))
555 unsigned Type = getOpenMPSimpleClauseType(
556 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
557 SourceLocation TypeLoc = Tok.getLocation();
558 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
559 Tok.isNot(tok::annot_pragma_openmp_end))
565 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
569 /// \brief Parsing of OpenMP clauses like 'ordered'.
580 /// mergeable-clause:
586 OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
587 SourceLocation Loc = Tok.getLocation();
590 return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
594 /// \brief Parsing of OpenMP clauses with single expressions and some additional
595 /// argument like 'schedule' or 'dist_schedule'.
598 /// 'schedule' '(' kind [',' expression ] ')'
600 OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) {
601 SourceLocation Loc = ConsumeToken();
602 SourceLocation CommaLoc;
604 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
605 if (T.expectAndConsume(diag::err_expected_lparen_after,
606 getOpenMPClauseName(Kind)))
610 unsigned Type = getOpenMPSimpleClauseType(
611 Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok));
612 SourceLocation KLoc = Tok.getLocation();
613 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
614 Tok.isNot(tok::annot_pragma_openmp_end))
617 if (Kind == OMPC_schedule &&
618 (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic ||
619 Type == OMPC_SCHEDULE_guided) &&
620 Tok.is(tok::comma)) {
621 CommaLoc = ConsumeAnyToken();
622 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
623 Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional);
631 return Actions.ActOnOpenMPSingleExprWithArgClause(
632 Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc,
633 T.getCloseLocation());
636 static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
637 UnqualifiedId &ReductionId) {
638 SourceLocation TemplateKWLoc;
639 if (ReductionIdScopeSpec.isEmpty()) {
641 switch (P.getCurToken().getKind()) {
669 if (OOK != OO_None) {
670 SourceLocation OpLoc = P.ConsumeToken();
671 SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
672 ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
676 return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
677 /*AllowDestructorName*/ false,
678 /*AllowConstructorName*/ false, ParsedType(),
679 TemplateKWLoc, ReductionId);
682 /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate',
683 /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'.
686 /// 'private' '(' list ')'
687 /// firstprivate-clause:
688 /// 'firstprivate' '(' list ')'
689 /// lastprivate-clause:
690 /// 'lastprivate' '(' list ')'
692 /// 'shared' '(' list ')'
694 /// 'linear' '(' list [ ':' linear-step ] ')'
696 /// 'aligned' '(' list [ ':' alignment ] ')'
697 /// reduction-clause:
698 /// 'reduction' '(' reduction-identifier ':' list ')'
699 /// copyprivate-clause:
700 /// 'copyprivate' '(' list ')'
702 /// 'flush' '(' list ')'
704 /// 'depend' '(' in | out | inout : list ')'
706 OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
707 SourceLocation Loc = Tok.getLocation();
708 SourceLocation LOpen = ConsumeToken();
709 SourceLocation ColonLoc = SourceLocation();
710 // Optional scope specifier and unqualified id for reduction identifier.
711 CXXScopeSpec ReductionIdScopeSpec;
712 UnqualifiedId ReductionId;
713 bool InvalidReductionId = false;
714 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
715 SourceLocation DepLoc;
718 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
719 if (T.expectAndConsume(diag::err_expected_lparen_after,
720 getOpenMPClauseName(Kind)))
723 // Handle reduction-identifier for reduction clause.
724 if (Kind == OMPC_reduction) {
725 ColonProtectionRAIIObject ColonRAII(*this);
726 if (getLangOpts().CPlusPlus) {
727 ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false);
730 ParseReductionId(*this, ReductionIdScopeSpec, ReductionId);
731 if (InvalidReductionId) {
732 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
735 if (Tok.is(tok::colon)) {
736 ColonLoc = ConsumeToken();
738 Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier";
740 } else if (Kind == OMPC_depend) {
741 // Handle dependency type for depend clause.
742 ColonProtectionRAIIObject ColonRAII(*this);
743 DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType(
744 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""));
745 DepLoc = Tok.getLocation();
747 if (DepKind == OMPC_DEPEND_unknown) {
748 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
753 if (Tok.is(tok::colon)) {
754 ColonLoc = ConsumeToken();
756 Diag(Tok, diag::warn_pragma_expected_colon) << "dependency type";
760 SmallVector<Expr *, 5> Vars;
761 bool IsComma = ((Kind != OMPC_reduction) && (Kind != OMPC_depend)) ||
762 ((Kind == OMPC_reduction) && !InvalidReductionId) ||
763 ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown);
764 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
765 while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
766 Tok.isNot(tok::annot_pragma_openmp_end))) {
767 ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail);
770 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
771 if (VarExpr.isUsable()) {
772 Vars.push_back(VarExpr.get());
774 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
778 IsComma = Tok.is(tok::comma);
781 else if (Tok.isNot(tok::r_paren) &&
782 Tok.isNot(tok::annot_pragma_openmp_end) &&
783 (!MayHaveTail || Tok.isNot(tok::colon)))
784 Diag(Tok, diag::err_omp_expected_punc)
785 << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush)
786 : getOpenMPClauseName(Kind))
787 << (Kind == OMPC_flush);
790 // Parse ':' linear-step (or ':' alignment).
791 Expr *TailExpr = nullptr;
792 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
794 ColonLoc = Tok.getLocation();
797 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
799 TailExpr = Tail.get();
801 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
807 if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) ||
808 (Kind != OMPC_depend && Vars.empty()) || (MustHaveTail && !TailExpr) ||
812 return Actions.ActOnOpenMPVarListClause(
813 Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(),
814 ReductionIdScopeSpec,
815 ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId)
816 : DeclarationNameInfo(),