20 #include "llvm/ADT/PointerIntPair.h" 22 using namespace clang;
42 OMPD_distribute_parallel,
43 OMPD_teams_distribute_parallel,
44 OMPD_target_teams_distribute_parallel
47 class ThreadprivateListParserHelper final {
52 ThreadprivateListParserHelper(
Parser *P) :
P(P) {}
57 Identifiers.push_back(Res.
get());
70 return llvm::StringSwitch<unsigned>(S)
71 .Case(
"cancellation", OMPD_cancellation)
72 .Case(
"data", OMPD_data)
73 .Case(
"declare", OMPD_declare)
74 .Case(
"end", OMPD_end)
75 .Case(
"enter", OMPD_enter)
76 .Case(
"exit", OMPD_exit)
77 .Case(
"point", OMPD_point)
78 .Case(
"reduction", OMPD_reduction)
79 .Case(
"update", OMPD_update)
87 static const unsigned F[][3] = {
88 {OMPD_cancellation, OMPD_point, OMPD_cancellation_point},
89 {OMPD_declare, OMPD_reduction, OMPD_declare_reduction},
90 {OMPD_declare, OMPD_simd, OMPD_declare_simd},
91 {OMPD_declare, OMPD_target, OMPD_declare_target},
92 {OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel},
93 {OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for},
94 {OMPD_distribute_parallel_for, OMPD_simd,
95 OMPD_distribute_parallel_for_simd},
96 {OMPD_distribute, OMPD_simd, OMPD_distribute_simd},
97 {OMPD_end, OMPD_declare, OMPD_end_declare},
98 {OMPD_end_declare, OMPD_target, OMPD_end_declare_target},
99 {OMPD_target, OMPD_data, OMPD_target_data},
100 {OMPD_target, OMPD_enter, OMPD_target_enter},
101 {OMPD_target, OMPD_exit, OMPD_target_exit},
102 {OMPD_target, OMPD_update, OMPD_target_update},
103 {OMPD_target_enter, OMPD_data, OMPD_target_enter_data},
104 {OMPD_target_exit, OMPD_data, OMPD_target_exit_data},
105 {OMPD_for, OMPD_simd, OMPD_for_simd},
106 {OMPD_parallel, OMPD_for, OMPD_parallel_for},
107 {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
108 {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
109 {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd},
110 {OMPD_target, OMPD_parallel, OMPD_target_parallel},
111 {OMPD_target, OMPD_simd, OMPD_target_simd},
112 {OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for},
113 {OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd},
114 {OMPD_teams, OMPD_distribute, OMPD_teams_distribute},
115 {OMPD_teams_distribute, OMPD_simd, OMPD_teams_distribute_simd},
116 {OMPD_teams_distribute, OMPD_parallel, OMPD_teams_distribute_parallel},
117 {OMPD_teams_distribute_parallel, OMPD_for,
118 OMPD_teams_distribute_parallel_for},
119 {OMPD_teams_distribute_parallel_for, OMPD_simd,
120 OMPD_teams_distribute_parallel_for_simd},
121 {OMPD_target, OMPD_teams, OMPD_target_teams},
122 {OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute},
123 {OMPD_target_teams_distribute, OMPD_parallel,
124 OMPD_target_teams_distribute_parallel},
125 {OMPD_target_teams_distribute, OMPD_simd,
126 OMPD_target_teams_distribute_simd},
127 {OMPD_target_teams_distribute_parallel, OMPD_for,
128 OMPD_target_teams_distribute_parallel_for},
129 {OMPD_target_teams_distribute_parallel_for, OMPD_simd,
130 OMPD_target_teams_distribute_parallel_for_simd}};
131 enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 };
140 for (
unsigned I = 0; I < llvm::array_lengthof(F); ++I) {
141 if (DKind != F[I][0])
152 if (SDKind == F[I][1]) {
157 return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind)
166 bool WithOperator =
false;
167 if (Tok.
is(tok::kw_operator)) {
197 case tok::identifier:
202 P.
Diag(Tok.
getLocation(), diag::err_omp_expected_reduction_identifier);
203 P.
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
210 : DeclNames.getCXXOperatorName(OOK);
229 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
230 return DeclGroupPtrTy();
234 if (Name.
isEmpty() &&
Tok.
is(tok::annot_pragma_openmp_end))
235 return DeclGroupPtrTy();
238 bool IsCorrect = !ExpectAndConsume(tok::colon);
240 if (!IsCorrect &&
Tok.
is(tok::annot_pragma_openmp_end))
241 return DeclGroupPtrTy();
243 IsCorrect = IsCorrect && !Name.
isEmpty();
245 if (
Tok.
is(tok::colon) ||
Tok.
is(tok::annot_pragma_openmp_end)) {
246 Diag(
Tok.getLocation(), diag::err_expected_type);
250 if (!IsCorrect &&
Tok.
is(tok::annot_pragma_openmp_end))
251 return DeclGroupPtrTy();
262 Actions.ActOnOpenMPDeclareReductionType(Range.
getBegin(), TR);
263 if (!ReductionType.
isNull()) {
264 ReductionTypes.push_back(
265 std::make_pair(ReductionType, Range.
getBegin()));
268 SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end,
272 if (
Tok.
is(tok::colon) ||
Tok.
is(tok::annot_pragma_openmp_end))
276 if (ExpectAndConsume(tok::comma)) {
278 if (
Tok.
is(tok::annot_pragma_openmp_end)) {
279 Diag(
Tok.getLocation(), diag::err_expected_type);
280 return DeclGroupPtrTy();
283 }
while (
Tok.
isNot(tok::annot_pragma_openmp_end));
285 if (ReductionTypes.empty()) {
286 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
287 return DeclGroupPtrTy();
290 if (!IsCorrect &&
Tok.
is(tok::annot_pragma_openmp_end))
291 return DeclGroupPtrTy();
294 if (ExpectAndConsume(tok::colon))
297 if (
Tok.
is(tok::annot_pragma_openmp_end)) {
298 Diag(
Tok.getLocation(), diag::err_expected_expression);
299 return DeclGroupPtrTy();
302 DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart(
303 getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS);
307 unsigned I = 0, E = ReductionTypes.size();
308 for (
Decl *D : DRD.get()) {
309 TentativeParsingAction TPA(*
this);
314 Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D);
316 Actions.ActOnFinishFullExpr(ParseAssignmentExpression().
get(),
317 D->getLocation(),
false);
318 Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.
get());
321 Tok.
isNot(tok::annot_pragma_openmp_end)) {
328 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
330 if (
Tok.
is(tok::identifier) &&
331 Tok.getIdentifierInfo()->isStr(
"initializer")) {
334 Diag(
Tok.getLocation(), diag::err_expected) <<
"'initializer'";
341 tok::annot_pragma_openmp_end);
345 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
351 Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(),
354 if (
Tok.
is(tok::identifier) &&
355 Tok.getIdentifierInfo()->isStr(
"omp_priv")) {
356 if (Actions.getLangOpts().CPlusPlus) {
357 InitializerResult = Actions.ActOnFinishFullExpr(
358 ParseAssignmentExpression().
get(), D->getLocation(),
362 ParseOpenMPReductionInitializerForDecl(OmpPrivParm);
365 InitializerResult = Actions.ActOnFinishFullExpr(
366 ParseAssignmentExpression().
get(), D->getLocation(),
369 Actions.ActOnOpenMPDeclareReductionInitializerEnd(
370 D, InitializerResult.
get(), OmpPrivParm);
372 Tok.
isNot(tok::annot_pragma_openmp_end)) {
390 return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD,
394 void Parser::ParseOpenMPReductionInitializerForDecl(
VarDecl *OmpPrivParm) {
397 if (isTokenEqualOrEqualTypo()) {
400 if (
Tok.
is(tok::code_completion)) {
401 Actions.CodeCompleteInitializer(getCurScope(), OmpPrivParm);
402 Actions.FinalizeDeclaration(OmpPrivParm);
410 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
411 Actions.ActOnInitializerError(OmpPrivParm);
413 Actions.AddInitializerToDecl(OmpPrivParm, Init.
get(),
416 }
else if (
Tok.
is(tok::l_paren)) {
422 CommaLocsTy CommaLocs;
425 if (ParseExpressionList(
426 Exprs, CommaLocs, [
this, OmpPrivParm, LParLoc, &Exprs] {
427 QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
431 CalledSignatureHelp =
true;
432 Actions.CodeCompleteExpression(getCurScope(), PreferredType);
434 if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
435 Actions.ProduceConstructorSignatureHelp(
438 CalledSignatureHelp =
true;
440 Actions.ActOnInitializerError(OmpPrivParm);
441 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
448 assert(!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() &&
449 "Unexpected number of commas!");
453 Actions.AddInitializerToDecl(OmpPrivParm, Initializer.get(),
456 }
else if (getLangOpts().CPlusPlus11 &&
Tok.
is(tok::l_brace)) {
458 Diag(
Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
463 Actions.ActOnInitializerError(OmpPrivParm);
465 Actions.AddInitializerToDecl(OmpPrivParm, Init.
get(),
469 Actions.ActOnUninitializedDecl(OmpPrivParm);
479 class FNContextRAII final {
484 bool HasTemplateScope =
false;
485 bool HasFunScope =
false;
486 FNContextRAII() =
delete;
487 FNContextRAII(
const FNContextRAII &) =
delete;
488 FNContextRAII &operator=(
const FNContextRAII &) =
delete;
505 if (HasTemplateScope)
506 Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D);
514 Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D);
521 if (HasTemplateScope)
544 bool IsError =
false;
545 while (Tok.
isNot(tok::annot_pragma_openmp_end)) {
546 if (Tok.
isNot(tok::identifier))
548 OMPDeclareSimdDeclAttr::BranchStateTy Out;
550 StringRef ClauseName = II->
getName();
552 if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) {
553 if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) {
554 P.
Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch)
556 << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange;
562 }
else if (ClauseName.equals(
"simdlen")) {
564 P.
Diag(Tok, diag::err_omp_more_one_clause)
576 CKind == OMPC_linear) {
579 if (CKind == OMPC_aligned)
581 else if (CKind == OMPC_linear)
588 if (CKind == OMPC_aligned) {
589 Alignments.append(Aligneds.size() - Alignments.size(), Data.
TailExpr);
590 }
else if (CKind == OMPC_linear) {
593 Data.
LinKind = OMPC_LINEAR_val;
594 LinModifiers.append(Linears.size() - LinModifiers.size(),
596 Steps.append(Linears.size() - Steps.size(), Data.
TailExpr);
603 if (Tok.
is(tok::comma))
614 PP.EnterTokenStream(Toks,
true);
616 ConsumeAnyToken(
true);
618 FNContextRAII FnContext(*
this, Ptr);
619 OMPDeclareSimdDeclAttr::BranchStateTy BS =
620 OMPDeclareSimdDeclAttr::BS_Undefined;
630 Alignments, Linears, LinModifiers, Steps);
632 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
633 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
635 while (
Tok.
isNot(tok::annot_pragma_openmp_end))
642 return Actions.ActOnOpenMPDeclareSimdDirective(
643 Ptr, BS, Simdlen.
get(), Uniforms, Aligneds, Alignments, Linears,
650 while (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
651 OMPDeclareTargetDeclAttr::MapTypeTy MT = OMPDeclareTargetDeclAttr::MT_To;
652 if (
Tok.
is(tok::identifier)) {
654 StringRef ClauseName = II->
getName();
656 if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, MT)) {
657 Diag(
Tok, diag::err_omp_declare_target_unexpected_clause) << ClauseName;
662 auto &&Callback = [
this, MT, &SameDirectiveDecls](
664 Actions.ActOnOpenMPDeclareTargetName(getCurScope(), SS, NameInfo, MT,
667 if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback,
672 if (
Tok.
is(tok::comma))
675 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
678 SameDirectiveDecls.end());
680 return DeclGroupPtrTy();
681 return Actions.BuildDeclaratorGroup(Decls);
686 if (DKind != OMPD_end_declare_target) {
687 Diag(
Tok, diag::err_expected_end_declare_target);
688 Diag(DTLoc, diag::note_matching) <<
"'#pragma omp declare target'";
692 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
693 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
695 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
723 assert(
Tok.
is(tok::annot_pragma_openmp) &&
"Not an OpenMP directive!");
730 case OMPD_threadprivate: {
732 ThreadprivateListParserHelper Helper(
this);
733 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper,
true)) {
736 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
737 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
739 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
742 ConsumeAnnotationToken();
743 return Actions.ActOnOpenMPThreadprivateDirective(Loc,
744 Helper.getIdentifiers());
748 case OMPD_requires: {
753 if (
Tok.
is(tok::annot_pragma_openmp_end)) {
754 Diag(
Tok, diag::err_omp_expected_clause)
758 while (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
762 Actions.StartOpenMPClause(CKind);
764 ParseOpenMPClause(OMPD_requires, CKind, !FirstClauses[CKind].getInt());
765 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, StopBeforeMatch);
766 FirstClauses[CKind].setInt(
true);
767 if (Clause !=
nullptr)
768 Clauses.push_back(Clause);
769 if (
Tok.
is(tok::annot_pragma_openmp_end)) {
770 Actions.EndOpenMPClause();
774 if (
Tok.
is(tok::comma))
776 Actions.EndOpenMPClause();
779 if (Clauses.size() == 0) {
780 Diag(
Tok, diag::err_omp_expected_clause)
782 ConsumeAnnotationToken();
785 ConsumeAnnotationToken();
786 return Actions.ActOnOpenMPRequiresDirective(StartLoc, Clauses);
788 case OMPD_declare_reduction:
790 if (DeclGroupPtrTy Res = ParseOpenMPDeclareReductionDirective(AS)) {
793 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
794 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
796 while (
Tok.
isNot(tok::annot_pragma_openmp_end))
800 ConsumeAnnotationToken();
804 case OMPD_declare_simd: {
811 while(
Tok.
isNot(tok::annot_pragma_openmp_end)) {
819 if (
Tok.
is(tok::annot_pragma_openmp)) {
820 Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs,
TagType, Tag);
821 }
else if (
Tok.
isNot(tok::r_brace) && !isEofOrEom()) {
825 MaybeParseCXX11Attributes(Attrs);
827 Ptr = ParseExternalDeclaration(Attrs, &PDS);
830 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs,
TagType, Tag);
834 Diag(Loc, diag::err_omp_decl_in_declare_simd);
835 return DeclGroupPtrTy();
837 return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc);
839 case OMPD_declare_target: {
841 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
842 return ParseOMPDeclareTargetClauses();
848 if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc))
849 return DeclGroupPtrTy();
859 MaybeParseCXX11Attributes(Attrs);
861 Ptr = ParseExternalDeclaration(Attrs, &PDS);
864 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs,
TagType, Tag);
868 Decls.append(Ref.
begin(), Ref.
end());
870 if (
Tok.isAnnotation() &&
Tok.
is(tok::annot_pragma_openmp)) {
871 TentativeParsingAction TPA(*
this);
872 ConsumeAnnotationToken();
874 if (DKind != OMPD_end_declare_target)
881 ParseOMPEndDeclareTargetDirective(DKind, DTLoc);
882 Actions.ActOnFinishOpenMPDeclareTargetDirective();
883 return Actions.BuildDeclaratorGroup(Decls);
886 Diag(
Tok, diag::err_omp_unknown_directive);
904 case OMPD_parallel_for:
905 case OMPD_parallel_for_simd:
906 case OMPD_parallel_sections:
910 case OMPD_cancellation_point:
912 case OMPD_target_data:
913 case OMPD_target_enter_data:
914 case OMPD_target_exit_data:
915 case OMPD_target_parallel:
916 case OMPD_target_parallel_for:
918 case OMPD_taskloop_simd:
919 case OMPD_distribute:
920 case OMPD_end_declare_target:
921 case OMPD_target_update:
922 case OMPD_distribute_parallel_for:
923 case OMPD_distribute_parallel_for_simd:
924 case OMPD_distribute_simd:
925 case OMPD_target_parallel_for_simd:
926 case OMPD_target_simd:
927 case OMPD_teams_distribute:
928 case OMPD_teams_distribute_simd:
929 case OMPD_teams_distribute_parallel_for_simd:
930 case OMPD_teams_distribute_parallel_for:
931 case OMPD_target_teams:
932 case OMPD_target_teams_distribute:
933 case OMPD_target_teams_distribute_parallel_for:
934 case OMPD_target_teams_distribute_parallel_for_simd:
935 case OMPD_target_teams_distribute_simd:
936 Diag(
Tok, diag::err_omp_unexpected_directive)
940 while (
Tok.
isNot(tok::annot_pragma_openmp_end))
979 StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
980 AllowedConstructsKind Allowed) {
981 assert(
Tok.
is(tok::annot_pragma_openmp) &&
"Not an OpenMP directive!");
994 bool HasAssociatedStatement =
true;
995 bool FlushHasClause =
false;
998 case OMPD_threadprivate: {
999 if (Allowed != ACK_Any) {
1000 Diag(
Tok, diag::err_omp_immediate_directive)
1004 ThreadprivateListParserHelper Helper(
this);
1005 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper,
false)) {
1008 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
1009 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
1011 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
1013 DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective(
1014 Loc, Helper.getIdentifiers());
1015 Directive = Actions.ActOnDeclStmt(Res, Loc,
Tok.getLocation());
1017 SkipUntil(tok::annot_pragma_openmp_end);
1020 case OMPD_declare_reduction:
1022 if (DeclGroupPtrTy Res =
1023 ParseOpenMPDeclareReductionDirective(
AS_none)) {
1026 if (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
1027 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
1029 while (
Tok.
isNot(tok::annot_pragma_openmp_end))
1033 Directive = Actions.ActOnDeclStmt(Res, Loc,
Tok.getLocation());
1035 SkipUntil(tok::annot_pragma_openmp_end);
1039 if (PP.LookAhead(0).is(tok::l_paren)) {
1040 FlushHasClause =
true;
1046 case OMPD_taskyield:
1049 case OMPD_cancellation_point:
1051 case OMPD_target_enter_data:
1052 case OMPD_target_exit_data:
1053 case OMPD_target_update:
1054 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
1055 Diag(
Tok, diag::err_omp_immediate_directive)
1058 HasAssociatedStatement =
false;
1070 case OMPD_parallel_for:
1071 case OMPD_parallel_for_simd:
1072 case OMPD_parallel_sections:
1078 case OMPD_taskgroup:
1079 case OMPD_target_data:
1080 case OMPD_target_parallel:
1081 case OMPD_target_parallel_for:
1083 case OMPD_taskloop_simd:
1084 case OMPD_distribute:
1085 case OMPD_distribute_parallel_for:
1086 case OMPD_distribute_parallel_for_simd:
1087 case OMPD_distribute_simd:
1088 case OMPD_target_parallel_for_simd:
1089 case OMPD_target_simd:
1090 case OMPD_teams_distribute:
1091 case OMPD_teams_distribute_simd:
1092 case OMPD_teams_distribute_parallel_for_simd:
1093 case OMPD_teams_distribute_parallel_for:
1094 case OMPD_target_teams:
1095 case OMPD_target_teams_distribute:
1096 case OMPD_target_teams_distribute_parallel_for:
1097 case OMPD_target_teams_distribute_parallel_for_simd:
1098 case OMPD_target_teams_distribute_simd: {
1101 if (DKind == OMPD_critical) {
1103 tok::annot_pragma_openmp_end);
1105 if (
Tok.isAnyIdentifier()) {
1110 Diag(
Tok, diag::err_omp_expected_identifier_for_critical);
1114 }
else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
1116 if (
Tok.
isNot(tok::annot_pragma_openmp_end))
1124 ParseScope OMPDirectiveScope(
this, ScopeFlags);
1125 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
1127 while (
Tok.
isNot(tok::annot_pragma_openmp_end)) {
1131 : FlushHasClause ? OMPC_flush
1133 Actions.StartOpenMPClause(CKind);
1134 FlushHasClause =
false;
1136 ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt());
1137 FirstClauses[CKind].setInt(
true);
1139 FirstClauses[CKind].setPointer(Clause);
1140 Clauses.push_back(Clause);
1144 if (
Tok.
is(tok::comma))
1146 Actions.EndOpenMPClause();
1149 EndLoc =
Tok.getLocation();
1151 ConsumeAnnotationToken();
1156 if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) {
1157 if (Allowed == ACK_StatementsOpenMPNonStandalone) {
1158 Diag(Loc, diag::err_omp_immediate_directive)
1162 HasAssociatedStatement =
false;
1166 if (HasAssociatedStatement) {
1168 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
1173 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
1174 }
else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data ||
1175 DKind == OMPD_target_exit_data) {
1176 Actions.ActOnOpenMPRegionStart(DKind, getCurScope());
1178 Actions.ActOnCompoundStmt(Loc, Loc,
llvm::None,
1180 AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
1182 Directive = Actions.ActOnOpenMPExecutableDirective(
1183 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc,
1187 Actions.EndOpenMPDSABlock(Directive.get());
1188 OMPDirectiveScope.Exit();
1191 case OMPD_declare_simd:
1192 case OMPD_declare_target:
1193 case OMPD_end_declare_target:
1195 Diag(
Tok, diag::err_omp_unexpected_directive)
1197 SkipUntil(tok::annot_pragma_openmp_end);
1200 Diag(
Tok, diag::err_omp_unknown_directive);
1201 SkipUntil(tok::annot_pragma_openmp_end);
1211 bool Parser::ParseOpenMPSimpleVarList(
1215 bool AllowScopeSpecifier) {
1221 bool IsCorrect =
true;
1222 bool NoIdentIsFound =
true;
1225 while (
Tok.
isNot(tok::r_paren) &&
Tok.
isNot(tok::annot_pragma_openmp_end)) {
1230 NoIdentIsFound =
false;
1232 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
1233 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
false)) {
1235 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1237 }
else if (ParseUnqualifiedId(SS,
false,
false,
false,
false,
nullptr,
1240 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1243 Tok.
isNot(tok::annot_pragma_openmp_end)) {
1245 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1251 Callback(SS, Actions.GetNameFromUnqualifiedId(Name));
1254 if (
Tok.
is(tok::comma)) {
1259 if (NoIdentIsFound) {
1260 Diag(
Tok, diag::err_expected) << tok::identifier;
1289 bool ErrorFound =
false;
1290 bool WrongDirective =
false;
1296 WrongDirective =
true;
1301 case OMPC_num_threads:
1307 case OMPC_num_teams:
1308 case OMPC_thread_limit:
1310 case OMPC_grainsize:
1311 case OMPC_num_tasks:
1334 Diag(
Tok, diag::err_omp_more_one_clause)
1339 if (CKind == OMPC_ordered && PP.LookAhead(0).isNot(tok::l_paren))
1340 Clause = ParseOpenMPClause(CKind, WrongDirective);
1342 Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
1345 case OMPC_proc_bind:
1346 case OMPC_atomic_default_mem_order:
1356 Diag(
Tok, diag::err_omp_more_one_clause)
1361 Clause = ParseOpenMPSimpleClause(CKind, WrongDirective);
1364 case OMPC_dist_schedule:
1365 case OMPC_defaultmap:
1371 Diag(
Tok, diag::err_omp_more_one_clause)
1378 Clause = ParseOpenMPSingleExprWithArgClause(CKind, WrongDirective);
1382 case OMPC_mergeable:
1391 case OMPC_unified_address:
1392 case OMPC_unified_shared_memory:
1393 case OMPC_reverse_offload:
1394 case OMPC_dynamic_allocators:
1402 Diag(
Tok, diag::err_omp_more_one_clause)
1407 Clause = ParseOpenMPClause(CKind, WrongDirective);
1410 case OMPC_firstprivate:
1411 case OMPC_lastprivate:
1413 case OMPC_reduction:
1414 case OMPC_task_reduction:
1415 case OMPC_in_reduction:
1419 case OMPC_copyprivate:
1425 case OMPC_use_device_ptr:
1426 case OMPC_is_device_ptr:
1427 Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective);
1430 Diag(
Tok, diag::warn_omp_extra_tokens_at_eol)
1432 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
1436 if (!WrongDirective)
1437 Diag(
Tok, diag::err_omp_unexpected_clause)
1439 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
1442 return ErrorFound ? nullptr : Clause;
1451 if (T.
expectAndConsume(diag::err_expected_lparen_after, ClauseName.data()))
1456 false,
false, NotTypeCast));
1458 Val = Actions.ActOnFinishFullExpr(Val.
get(), ELoc,
false);
1461 RLoc =
Tok.getLocation();
1512 return Actions.ActOnOpenMPSingleExprClause(
Kind, Val.
get(), Loc, LLoc, RLoc);
1534 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok));
1537 Tok.
isNot(tok::annot_pragma_openmp_end))
1547 return Actions.ActOnOpenMPSimpleClause(
Kind, Type, TypeLoc, LOpen, Loc, RLoc);
1582 return Actions.ActOnOpenMPClause(
Kind, Loc,
Tok.getLocation());
1612 if (
Kind == OMPC_schedule) {
1613 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
1614 Arg.resize(NumberOfElements);
1615 KLoc.resize(NumberOfElements);
1620 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok));
1623 Arg[Modifier1] = KindModifier;
1624 KLoc[Modifier1] =
Tok.getLocation();
1626 Tok.
isNot(tok::annot_pragma_openmp_end))
1628 if (
Tok.
is(tok::comma)) {
1632 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok));
1636 KLoc[Modifier2] =
Tok.getLocation();
1638 Tok.
isNot(tok::annot_pragma_openmp_end))
1642 if (
Tok.
is(tok::colon))
1645 Diag(
Tok, diag::warn_pragma_expected_colon) <<
"schedule modifier";
1647 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok));
1649 Arg[ScheduleKind] = KindModifier;
1650 KLoc[ScheduleKind] =
Tok.getLocation();
1652 Tok.
isNot(tok::annot_pragma_openmp_end))
1654 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
1655 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
1656 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
1658 DelimLoc = ConsumeAnyToken();
1659 }
else if (
Kind == OMPC_dist_schedule) {
1661 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok)));
1662 KLoc.push_back(
Tok.getLocation());
1664 Tok.
isNot(tok::annot_pragma_openmp_end))
1666 if (Arg.back() == OMPC_DIST_SCHEDULE_static &&
Tok.
is(tok::comma))
1667 DelimLoc = ConsumeAnyToken();
1668 }
else if (
Kind == OMPC_defaultmap) {
1671 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok)));
1672 KLoc.push_back(
Tok.getLocation());
1674 Tok.
isNot(tok::annot_pragma_openmp_end))
1677 if (
Tok.
is(tok::colon))
1680 Diag(
Tok, diag::warn_pragma_expected_colon) <<
"defaultmap modifier";
1683 Kind,
Tok.isAnnotation() ?
"" : PP.getSpelling(
Tok)));
1684 KLoc.push_back(
Tok.getLocation());
1686 Tok.
isNot(tok::annot_pragma_openmp_end))
1689 assert(
Kind == OMPC_if);
1690 KLoc.push_back(
Tok.getLocation());
1691 TentativeParsingAction TPA(*
this);
1695 if (
Tok.
is(tok::colon) && getLangOpts().OpenMP > 40) {
1697 DelimLoc = ConsumeToken();
1707 bool NeedAnExpression = (
Kind == OMPC_schedule && DelimLoc.
isValid()) ||
1708 (
Kind == OMPC_dist_schedule && DelimLoc.
isValid()) ||
1710 if (NeedAnExpression) {
1712 ExprResult LHS(ParseCastExpression(
false,
false, NotTypeCast));
1715 Actions.ActOnFinishFullExpr(Val.
get(), ELoc,
false);
1723 if (NeedAnExpression && Val.
isInvalid())
1728 return Actions.ActOnOpenMPSingleExprWithArgClause(
1734 if (ReductionIdScopeSpec.
isEmpty()) {
1775 nullptr,
nullptr, ReductionId);
1781 if (!Tok.
is(tok::identifier))
1787 return TypeModifier;
1799 if (TypeModifier == OMPC_MAP_MODIFIER_always ||
1800 TypeModifier == OMPC_MAP_MODIFIER_close) {
1808 if (Tok.
is(tok::comma)) {
1809 P.
Diag(Tok, diag::err_omp_map_type_modifier_missing);
1816 P.
Diag(Tok, diag::err_omp_unknown_map_type_modifier);
1828 if (!Tok.
isOneOf(tok::identifier, tok::kw_delete))
1841 if (Tok.
is(tok::colon)) {
1842 P.
Diag(Tok, diag::err_omp_map_type_missing);
1847 P.
Diag(Tok, diag::err_omp_unknown_map_type);
1857 bool InvalidReductionId =
false;
1865 bool NeedRParenForLinear =
false;
1867 tok::annot_pragma_openmp_end);
1869 if (Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
1870 Kind == OMPC_in_reduction) {
1877 UnqualifiedReductionId);
1878 if (InvalidReductionId) {
1879 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1882 if (
Tok.
is(tok::colon))
1885 Diag(
Tok, diag::warn_pragma_expected_colon) <<
"reduction identifier";
1886 if (!InvalidReductionId)
1888 Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId);
1889 }
else if (Kind == OMPC_depend) {
1894 Kind,
Tok.
is(tok::identifier) ? PP.getSpelling(
Tok) :
""));
1898 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1903 if (DKind == OMPD_ordered && Data.
DepKind == OMPC_DEPEND_source) {
1909 if (
Tok.
is(tok::colon)) {
1912 Diag(
Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren
1913 : diag::warn_pragma_expected_colon)
1914 <<
"dependency type";
1916 }
else if (Kind == OMPC_linear) {
1918 if (
Tok.
is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
1923 NeedRParenForLinear =
true;
1925 }
else if (Kind == OMPC_map) {
1935 TentativeParsingAction TPA(*
this);
1936 bool ColonPresent =
false;
1937 if (SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
1939 if (
Tok.
is(tok::colon))
1940 ColonPresent =
true;
1950 Data.
MapType = OMPC_MAP_tofrom;
1954 if (
Tok.
is(tok::colon))
1959 (Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
1960 Kind != OMPC_in_reduction && Kind != OMPC_depend && Kind != OMPC_map) ||
1961 (Kind == OMPC_reduction && !InvalidReductionId) ||
1964 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
1966 Tok.
isNot(tok::annot_pragma_openmp_end))) {
1970 Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
1972 Vars.push_back(VarExpr.
get());
1974 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1978 IsComma =
Tok.
is(tok::comma);
1981 else if (
Tok.
isNot(tok::r_paren) &&
1982 Tok.
isNot(tok::annot_pragma_openmp_end) &&
1983 (!MayHaveTail ||
Tok.
isNot(tok::colon)))
1984 Diag(
Tok, diag::err_omp_expected_punc)
1987 << (Kind == OMPC_flush);
1991 if (NeedRParenForLinear)
1995 const bool MustHaveTail = MayHaveTail &&
Tok.
is(tok::colon);
1999 ExprResult Tail = ParseAssignmentExpression();
2001 Actions.ActOnFinishFullExpr(Tail.
get(), ELoc,
false);
2005 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
2010 Data.
RLoc =
Tok.getLocation();
2015 (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) ||
2016 (MustHaveTail && !Data.
TailExpr) || InvalidReductionId;
2071 if (ParseOpenMPVarList(DKind,
Kind, Vars, Data))
2076 return Actions.ActOnOpenMPVarListClause(
OpenMPDependClauseKind DepKind
Defines the clang::ASTContext interface.
ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, const DeclarationNameInfo &Id)
Called on correct id-expression from the '#pragma omp threadprivate'.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
ParseScope - Introduces a new scope for parsing.
A (possibly-)qualified type.
DeclarationNameInfo ReductionId
static OpenMPDirectiveKind parseOpenMPDirectiveKind(Parser &P)
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
bool isEmpty() const
No scope specifier.
Decl - This represents one declaration (or definition), e.g.
SmallVector< OpenMPMapModifierKind, OMPMapClause::NumberOfModifiers > MapTypeModifiers
The base class of the type hierarchy.
SourceLocation getCloseLocation() const
This indicates that the scope corresponds to a function, which means that labels are set here...
bool isAllowedClauseForDirective(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind)
static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, UnqualifiedId &ReductionId)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
void ActOnExitFunctionContext()
Wrapper for void* pointer.
Parser - This implements a parser for the C family of languages.
bool isEmpty() const
Evaluates true when this declaration name is empty.
bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, SourceLocation LinLoc)
Checks correctness of linear modifiers.
SourceLocation DepLinMapLoc
Represents a variable declaration or definition.
ActionResult< Stmt * > StmtResult
TypeSpecifierType
Specifies the kind of type.
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing...
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
OpenMPLinearClauseKind LinKind
The collection of all-type qualifiers we support.
OpenMPMapModifierKind
OpenMP modifier kind for 'map' clause.
Base wrapper for a particular "section" of type source info.
Represents a struct/union/class.
const char * getOpenMPClauseName(OpenMPClauseKind Kind)
One of these records is kept for each identifier that is lexed.
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Token - This structure provides full information about a lexed token.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
Represents a C++ unqualified-id that has been parsed.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
OpenMPClauseKind getOpenMPClauseKind(llvm::StringRef Str)
static bool parseDeclareSimdClauses(Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen, SmallVectorImpl< Expr *> &Uniforms, SmallVectorImpl< Expr *> &Aligneds, SmallVectorImpl< Expr *> &Alignments, SmallVectorImpl< Expr *> &Linears, SmallVectorImpl< unsigned > &LinModifiers, SmallVectorImpl< Expr *> &Steps)
Parses clauses for 'declare simd' directive.
Represents a C++ nested-name-specifier or a global scope specifier.
Sema - This implements semantic analysis and AST building for C.
A RAII object to enter scope of a compound statement.
DeclarationNameTable DeclarationNames
This is the scope of OpenMP executable directive.
Sema & getActions() const
bool ParseUnqualifiedId(CXXScopeSpec &SS, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, ParsedType ObjectType, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
const Token & getCurToken() const
CXXScopeSpec ReductionIdScopeSpec
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
OpenMPClauseKind
OpenMP clauses.
DeclContext * getDeclContext()
This is a compound statement scope.
static void parseMapType(Parser &P, Parser::OpenMPVarListDataTy &Data)
Parse map-type in map clause.
Preprocessor & getPreprocessor() const
SmallVector< SourceLocation, OMPMapClause::NumberOfModifiers > MapTypeModifiersLoc
SourceLocation getOpenLocation() const
bool isNull() const
Return true if this QualType doesn't point to a type yet.
static OpenMPMapModifierKind isMapModifier(Parser &P)
Checks if the token is a valid map-type-modifier.
A class for parsing a DeclSpec.
bool isTemplateDecl() const
returns true if this declaration is a template
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
ASTContext & getASTContext() const
Encodes a location in the source.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr *> &Vars, OpenMPVarListDataTy &Data)
Parses clauses with list.
static unsigned getOpenMPDirectiveKindEx(StringRef S)
IdentifierInfo * getIdentifierInfo() const
OpenMPDirectiveKind
OpenMP directives.
This is a basic class for representing single OpenMP clause.
Scope * getCurScope() const
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc)
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
StringRef getName() const
Return the actual identifier string.
bool isNot(tok::TokenKind K) const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool expectAndConsume(unsigned DiagID=diag::err_expected, const char *Msg="", tok::TokenKind SkipToTok=tok::unknown)
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
This is the scope of some OpenMP simd directive.
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
static OpenMPMapClauseKind isMapType(Parser &P)
Checks if the token is a valid map-type.
This is a scope that corresponds to the template parameters of a C++ template.
The name of a declaration.
bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a simd directive.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Data used for parsing list of variables in OpenMP clauses.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
static const TST TST_unspecified
Not an overloaded operator.
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str)
QualType getCanonicalTypeInternal() const
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
This file defines OpenMP AST classes for executable directives and clauses.
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
OpenMPDirectiveKind getOpenMPDirectiveKind(llvm::StringRef Str)
const char * getOpenMPDirectiveName(OpenMPDirectiveKind Kind)
This is a scope that can contain a declaration.
static void parseMapTypeModifiers(Parser &P, Parser::OpenMPVarListDataTy &Data)
Parse map-type-modifiers in map clause.
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
static DeclarationName parseOpenMPReductionId(Parser &P)
This is the scope of some OpenMP loop directive.
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Directive - Abstract class representing a parsed verify directive.
SourceLocation getBegin() const
VerifyDiagnosticConsumer::Directive Directive
SourceLocation getLocation() const
OpenMPMapClauseKind MapType
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Stop skipping at specified token, but don't skip the token itself.
SourceLocation getEndLoc() const