26#include "llvm/ADT/SmallBitVector.h"
27#include "llvm/ADT/StringSwitch.h"
28#include "llvm/Frontend/OpenMP/DirectiveNameParser.h"
29#include "llvm/Frontend/OpenMP/OMPAssume.h"
30#include "llvm/Frontend/OpenMP/OMPContext.h"
35using namespace llvm::omp;
42class DeclDirectiveListParserHelper final {
43 SmallVector<Expr *, 4> Identifiers;
50 void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) {
51 ExprResult Res = P->getActions().OpenMP().ActOnOpenMPIdExpression(
52 P->getCurScope(), SS, NameInfo, Kind);
54 Identifiers.push_back(Res.
get());
56 llvm::ArrayRef<Expr *> getIdentifiers()
const {
return Identifiers; }
65 auto [D, VR] = getOpenMPDirectiveKindAndVersions(Name);
67 if (D == Directive::OMPD_ordered_blockassoc)
68 D = Directive::OMPD_ordered_standalone;
69 assert(D == Kind &&
"Directive kind mismatch");
73 P.
Diag(Loc, diag::warn_omp_future_directive_spelling) << Name;
79 static const DirectiveNameParser DirParser;
81 const DirectiveNameParser::State *S = DirParser.initial();
84 if (
Tok.isAnnotation())
90 S = DirParser.consume(S, Concat);
94 while (!
Tok.isAnnotation()) {
97 if (!
Tok.isAnnotation()) {
99 S = DirParser.consume(S, TS);
107 assert(S &&
"Should have exited early");
116 bool WithOperator =
false;
117 if (
Tok.is(tok::kw_operator)) {
122 switch (
Tok.getKind()) {
147 case tok::identifier:
152 P.
Diag(
Tok.getLocation(), diag::err_omp_expected_reduction_identifier);
153 P.
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
159 return OOK ==
OO_None ? DeclNames.getIdentifier(
Tok.getIdentifierInfo())
160 : DeclNames.getCXXOperatorName(OOK);
165 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
168 if (
T.expectAndConsume(
169 diag::err_expected_lparen_after,
170 getOpenMPDirectiveName(OMPD_declare_reduction, OMPVersion).data())) {
176 if (Name.
isEmpty() && Tok.is(tok::annot_pragma_openmp_end))
180 bool IsCorrect = !ExpectAndConsume(tok::colon);
182 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
185 IsCorrect = IsCorrect && !Name.
isEmpty();
187 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) {
188 Diag(Tok.getLocation(), diag::err_expected_type);
192 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
195 SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes;
202 QualType ReductionType = Actions.OpenMP().ActOnOpenMPDeclareReductionType(
203 Range.getBegin(), TR);
204 if (!ReductionType.
isNull()) {
205 ReductionTypes.push_back(
206 std::make_pair(ReductionType,
Range.getBegin()));
209 SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end,
213 if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end))
217 if (ExpectAndConsume(tok::comma)) {
219 if (Tok.is(tok::annot_pragma_openmp_end)) {
220 Diag(Tok.getLocation(), diag::err_expected_type);
224 }
while (Tok.isNot(tok::annot_pragma_openmp_end));
226 if (ReductionTypes.empty()) {
231 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
235 if (ExpectAndConsume(tok::colon))
238 if (Tok.is(tok::annot_pragma_openmp_end)) {
239 Diag(Tok.getLocation(), diag::err_expected_expression);
244 Actions.OpenMP().ActOnOpenMPDeclareReductionDirectiveStart(
245 getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes,
250 unsigned I = 0, E = ReductionTypes.size();
251 for (Decl *D : DRD.get()) {
252 TentativeParsingAction TPA(*
this);
257 Actions.OpenMP().ActOnOpenMPDeclareReductionCombinerStart(
getCurScope(), D);
258 ExprResult CombinerResult = Actions.ActOnFinishFullExpr(
260 Actions.OpenMP().ActOnOpenMPDeclareReductionCombinerEnd(
261 D, CombinerResult.
get());
263 if (CombinerResult.
isInvalid() && Tok.isNot(tok::r_paren) &&
264 Tok.isNot(tok::annot_pragma_openmp_end)) {
269 IsCorrect = !
T.consumeClose() && IsCorrect && CombinerResult.
isUsable();
271 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
273 if (Tok.is(tok::identifier) &&
274 Tok.getIdentifierInfo()->isStr(
"initializer")) {
277 Diag(Tok.getLocation(), diag::err_expected) <<
"'initializer'";
284 tok::annot_pragma_openmp_end);
286 !
T.expectAndConsume(diag::err_expected_lparen_after,
"initializer") &&
288 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
293 VarDecl *OmpPrivParm =
294 Actions.OpenMP().ActOnOpenMPDeclareReductionInitializerStart(
297 if (Tok.is(tok::identifier) &&
298 Tok.getIdentifierInfo()->isStr(
"omp_priv")) {
300 ParseOpenMPReductionInitializerForDecl(OmpPrivParm);
302 InitializerResult = Actions.ActOnFinishFullExpr(
306 Actions.OpenMP().ActOnOpenMPDeclareReductionInitializerEnd(
307 D, InitializerResult.
get(), OmpPrivParm);
308 if (InitializerResult.
isInvalid() && Tok.isNot(tok::r_paren) &&
309 Tok.isNot(tok::annot_pragma_openmp_end)) {
315 !
T.consumeClose() && IsCorrect && !InitializerResult.
isInvalid();
327 return Actions.OpenMP().ActOnOpenMPDeclareReductionDirectiveEnd(
331void Parser::ParseOpenMPReductionInitializerForDecl(
VarDecl *OmpPrivParm) {
334 if (isTokenEqualOrEqualTypo()) {
337 if (Tok.is(tok::code_completion)) {
339 Actions.CodeCompletion().CodeCompleteInitializer(
getCurScope(),
341 Actions.FinalizeDeclaration(OmpPrivParm);
345 PreferredType.enterVariableInit(Tok.getLocation(), OmpPrivParm);
348 if (
Init.isInvalid()) {
350 Actions.ActOnInitializerError(OmpPrivParm);
352 Actions.AddInitializerToDecl(OmpPrivParm,
Init.get(),
355 }
else if (Tok.is(tok::l_paren)) {
362 SourceLocation LParLoc =
T.getOpenLocation();
363 auto RunSignatureHelp = [
this, OmpPrivParm, LParLoc, &Exprs]() {
364 QualType PreferredType =
365 Actions.CodeCompletion().ProduceConstructorSignatureHelp(
367 OmpPrivParm->
getLocation(), Exprs, LParLoc,
false);
368 CalledSignatureHelp =
true;
369 return PreferredType;
371 if (ParseExpressionList(Exprs, [&] {
372 PreferredType.enterFunctionArgument(Tok.getLocation(),
375 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
377 Actions.ActOnInitializerError(OmpPrivParm);
381 SourceLocation RLoc = Tok.getLocation();
382 if (!
T.consumeClose())
383 RLoc =
T.getCloseLocation();
386 Actions.ActOnParenListExpr(
T.getOpenLocation(), RLoc, Exprs);
387 Actions.AddInitializerToDecl(OmpPrivParm,
Initializer.get(),
392 Diag(Tok, diag::compat_cxx11_generalized_initializer_lists);
396 if (
Init.isInvalid()) {
397 Actions.ActOnInitializerError(OmpPrivParm);
399 Actions.AddInitializerToDecl(OmpPrivParm,
Init.get(),
403 Actions.ActOnUninitializedDecl(OmpPrivParm);
409 bool IsCorrect =
true;
410 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
413 if (
T.expectAndConsume(
414 diag::err_expected_lparen_after,
415 getOpenMPDirectiveName(OMPD_declare_mapper, OMPVersion).data())) {
421 auto &DeclNames = Actions.getASTContext().DeclarationNames;
422 DeclarationName MapperId;
423 if (PP.LookAhead(0).is(tok::colon)) {
424 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) {
425 Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier);
428 MapperId = DeclNames.getIdentifier(Tok.getIdentifierInfo());
432 ExpectAndConsume(tok::colon);
436 DeclNames.getIdentifier(&Actions.getASTContext().Idents.get(
"default"));
439 if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end))
443 DeclarationName VName;
448 MapperType = Actions.OpenMP().ActOnOpenMPDeclareMapperType(
Range.getBegin(),
458 IsCorrect &= !
T.consumeClose();
466 DeclarationNameInfo DirName;
467 SourceLocation Loc = Tok.getLocation();
470 ParseScope OMPDirectiveScope(
this, ScopeFlags);
471 Actions.OpenMP().StartOpenMPDSABlock(OMPD_declare_mapper, DirName,
476 Actions.OpenMP().ActOnOpenMPDeclareMapperDirectiveVarDecl(
480 SmallVector<OMPClause *, 6> Clauses;
481 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
484 : getOpenMPClauseKind(PP.getSpelling(Tok));
485 Actions.OpenMP().StartOpenMPClause(CKind);
487 ParseOpenMPClause(OMPD_declare_mapper, CKind, Clauses.empty());
489 Clauses.push_back(Clause);
493 if (Tok.is(tok::comma))
495 Actions.OpenMP().EndOpenMPClause();
497 if (Clauses.empty()) {
498 Diag(Tok, diag::err_omp_expected_clause)
499 << getOpenMPDirectiveName(OMPD_declare_mapper, OMPVersion);
508 DeclGroupPtrTy DG = Actions.OpenMP().ActOnOpenMPDeclareMapperDirective(
509 OuterScope, Actions.getCurLexicalContext(), MapperId, MapperType,
510 Range.getBegin(), VName, AS, MapperVarRef.
get(), Clauses);
512 Actions.OpenMP().EndOpenMPDSABlock(
nullptr);
513 OMPDirectiveScope.Exit();
524 Parser::DeclSpecContext DSC = Parser::DeclSpecContext::DSC_type_specifier;
525 DeclSpec DS(AttrFactory);
526 ParseSpecifierQualifierList(DS, AS, DSC);
531 ParseDeclarator(DeclaratorInfo);
532 Range = DeclaratorInfo.getSourceRange();
533 if (DeclaratorInfo.getIdentifier() ==
nullptr) {
534 Diag(Tok.getLocation(), diag::err_omp_mapper_expected_declarator);
537 Name = Actions.GetNameForDeclarator(DeclaratorInfo).getName();
539 return Actions.OpenMP().ActOnOpenMPDeclareMapperVarDecl(
getCurScope(),
551 Actions.OpenMP().getOMPTraitInfoForSurroundingScope();
554 if (parseOMPDeclareVariantMatchClause(Loc, TI, ParentTI)) {
558 (void)ConsumeAnnotationToken();
563 skipUntilPragmaOpenMPEnd(OMPD_begin_declare_variant);
567 VariantMatchInfo VMI;
571 Loc](StringRef ISATrait) {
574 Diag(Loc, diag::warn_unknown_declare_variant_isa_trait) << ISATrait;
577 ASTCtx, std::move(DiagUnknownTrait),
580 Actions.OpenMP().getOpenMPDeviceNum());
582 if (isVariantApplicableInContext(VMI, OMPCtx,
584 Actions.OpenMP().ActOnOpenMPBeginDeclareVariant(Loc, TI);
589 unsigned Nesting = 1;
593 DKLoc = Tok.getLocation();
595 if (DK == OMPD_end_declare_variant)
597 else if (DK == OMPD_begin_declare_variant)
599 if (!Nesting || isEofOrEom())
604 parseOMPEndDirective(OMPD_begin_declare_variant, OMPD_end_declare_variant, DK,
615class FNContextRAII final {
619 bool HasFunScope =
false;
620 FNContextRAII() =
delete;
621 FNContextRAII(
const FNContextRAII &) =
delete;
622 FNContextRAII &operator=(
const FNContextRAII &) =
delete;
626 Decl *D = *Ptr.get().begin();
669 bool IsError =
false;
670 while (
Tok.isNot(tok::annot_pragma_openmp_end)) {
671 if (
Tok.isNot(tok::identifier))
673 OMPDeclareSimdDeclAttr::BranchStateTy Out;
675 StringRef ClauseName = II->
getName();
677 if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) {
678 if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) {
679 P.
Diag(
Tok, diag::err_omp_declare_simd_inbranch_notinbranch)
681 << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange;
687 }
else if (ClauseName ==
"simdlen") {
689 llvm::omp::Version OMPVersion =
691 P.
Diag(
Tok, diag::err_omp_more_one_clause)
692 << getOpenMPDirectiveName(OMPD_declare_simd, OMPVersion)
703 if (CKind == OMPC_uniform || CKind == OMPC_aligned ||
704 CKind == OMPC_linear) {
707 if (CKind == OMPC_aligned) {
709 }
else if (CKind == OMPC_linear) {
710 Data.ExtraModifier = OMPC_LINEAR_val;
717 getOpenMPClauseKind(ClauseName), *Vars,
Data,
720 if (CKind == OMPC_aligned) {
721 Alignments.append(Aligneds.size() - Alignments.size(),
722 Data.DepModOrTailExpr);
723 }
else if (CKind == OMPC_linear) {
724 assert(0 <=
Data.ExtraModifier &&
726 "Unexpected linear modifier.");
729 Data.ExtraModifierLoc))
730 Data.ExtraModifier = OMPC_LINEAR_val;
731 LinModifiers.append(Linears.size() - LinModifiers.size(),
733 Steps.append(Linears.size() - Steps.size(),
Data.DepModOrTailExpr);
740 if (
Tok.is(tok::comma))
749 PP.EnterToken(Tok,
true);
750 PP.EnterTokenStream(Toks,
true,
756 FNContextRAII FnContext(*
this, Ptr);
757 OMPDeclareSimdDeclAttr::BranchStateTy BS =
758 OMPDeclareSimdDeclAttr::BS_Undefined;
760 SmallVector<Expr *, 4> Uniforms;
761 SmallVector<Expr *, 4> Aligneds;
762 SmallVector<Expr *, 4> Alignments;
763 SmallVector<Expr *, 4> Linears;
764 SmallVector<unsigned, 4> LinModifiers;
765 SmallVector<Expr *, 4> Steps;
768 Alignments, Linears, LinModifiers, Steps);
769 skipUntilPragmaOpenMPEnd(OMPD_declare_simd);
771 SourceLocation EndLoc = ConsumeAnnotationToken();
774 return Actions.OpenMP().ActOnOpenMPDeclareSimdDirective(
775 Ptr, BS, Simdlen.
get(), Uniforms, Aligneds, Alignments, Linears,
776 LinModifiers, Steps, SourceRange(Loc, EndLoc));
783 CONTEXT_SELECTOR_SET_LVL = 0,
784 CONTEXT_SELECTOR_LVL = 1,
785 CONTEXT_TRAIT_LVL = 2,
788static StringRef stringLiteralParser(
Parser &P) {
795 if (
Tok.
is(tok::identifier) ||
Tok.
is(tok::kw_for)) {
803 return stringLiteralParser(P);
806 diag::warn_omp_declare_variant_string_literal_or_identifier)
811static bool checkForDuplicates(
Parser &P, StringRef Name,
813 llvm::StringMap<SourceLocation> &Seen,
815 auto Res = Seen.try_emplace(Name, NameLoc);
821 P.
Diag(NameLoc, diag::warn_omp_declare_variant_ctx_mutiple_use)
823 P.
Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here)
829void Parser::parseOMPTraitPropertyKind(OMPTraitProperty &TIProperty,
830 llvm::omp::TraitSet
Set,
832 llvm::StringMap<SourceLocation> &Seen) {
833 TIProperty.
Kind = TraitProperty::invalid;
835 SourceLocation NameLoc = Tok.getLocation();
837 if (Selector == llvm::omp::TraitSelector::target_device_device_num) {
839 TIProperty.
Kind = getOpenMPContextTraitPropertyKind(
Set, Selector, Name);
841 if (DeviceNumExprResult.
isUsable()) {
842 Expr *DeviceNumExpr = DeviceNumExprResult.
get();
843 Actions.OpenMP().ActOnOpenMPDeviceNum(DeviceNumExpr);
847 Name = getNameFromIdOrString(*
this, Tok, CONTEXT_TRAIT_LVL);
849 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
850 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(
Set, Selector);
855 TIProperty.
Kind = getOpenMPContextTraitPropertyKind(
Set, Selector, Name);
856 if (TIProperty.
Kind != TraitProperty::invalid) {
857 if (checkForDuplicates(*
this, Name, NameLoc, Seen, CONTEXT_TRAIT_LVL))
858 TIProperty.
Kind = TraitProperty::invalid;
864 Diag(NameLoc, diag::warn_omp_declare_variant_ctx_not_a_property)
865 << Name << getOpenMPContextTraitSelectorName(Selector)
866 << getOpenMPContextTraitSetName(
Set);
868 TraitSet SetForName = getOpenMPContextTraitSetKind(Name);
869 if (SetForName != TraitSet::invalid) {
870 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
871 << Name << CONTEXT_SELECTOR_SET_LVL << CONTEXT_TRAIT_LVL;
872 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
873 << Name <<
"<selector-name>"
874 <<
"(<property-name>)";
877 TraitSelector SelectorForName =
878 getOpenMPContextTraitSelectorKind(Name, SetForName);
879 if (SelectorForName != TraitSelector::invalid) {
880 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
881 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_TRAIT_LVL;
882 bool AllowsTraitScore =
false;
883 bool RequiresProperty =
false;
884 isValidTraitSelectorForTraitSet(
885 SelectorForName, getOpenMPContextTraitSetForSelector(SelectorForName),
886 AllowsTraitScore, RequiresProperty);
887 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
888 << getOpenMPContextTraitSetName(
889 getOpenMPContextTraitSetForSelector(SelectorForName))
890 << Name << (RequiresProperty ?
"(<property-name>)" :
"");
893 for (
const auto &PotentialSet :
894 {TraitSet::construct, TraitSet::user, TraitSet::implementation,
895 TraitSet::device, TraitSet::target_device}) {
896 TraitProperty PropertyForName =
897 getOpenMPContextTraitPropertyKind(PotentialSet, Selector, Name);
898 if (PropertyForName == TraitProperty::invalid)
900 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
901 << getOpenMPContextTraitSetName(
902 getOpenMPContextTraitSetForProperty(PropertyForName))
903 << getOpenMPContextTraitSelectorName(
904 getOpenMPContextTraitSelectorForProperty(PropertyForName))
905 << (
"(" + Name +
")").str();
908 Diag(NameLoc, diag::note_omp_declare_variant_ctx_options)
909 << CONTEXT_TRAIT_LVL << listOpenMPContextTraitProperties(
Set, Selector);
915 llvm::StringMap<SourceLocation> &Seen) {
916 assert(TISelector.
Kind ==
917 llvm::omp::TraitSelector::implementation_extension &&
918 "Only for extension properties, e.g., "
919 "`implementation={extension(PROPERTY)}`");
920 if (TIProperty.
Kind == TraitProperty::invalid)
923 if (TIProperty.
Kind ==
924 TraitProperty::implementation_extension_disable_implicit_base)
927 if (TIProperty.
Kind ==
928 TraitProperty::implementation_extension_allow_templates)
931 if (TIProperty.
Kind ==
932 TraitProperty::implementation_extension_bind_to_declaration)
937 llvm::omp::TraitProperty::implementation_extension_match_all ||
939 llvm::omp::TraitProperty::implementation_extension_match_any ||
941 llvm::omp::TraitProperty::implementation_extension_match_none);
944 if (IsMatchExtension(TIProperty)) {
946 if (IsMatchExtension(SeenProp)) {
947 P.
Diag(Loc, diag::err_omp_variant_ctx_second_match_extension);
948 StringRef SeenName = llvm::omp::getOpenMPContextTraitPropertyName(
951 P.
Diag(SeenLoc, diag::note_omp_declare_variant_ctx_used_here)
952 << CONTEXT_TRAIT_LVL << SeenName;
958 llvm_unreachable(
"Unknown extension property!");
961void Parser::parseOMPContextProperty(OMPTraitSelector &TISelector,
962 llvm::omp::TraitSet
Set,
963 llvm::StringMap<SourceLocation> &Seen) {
964 assert(TISelector.
Kind != TraitSelector::user_condition &&
965 "User conditions are special properties not handled here!");
967 SourceLocation PropertyLoc = Tok.getLocation();
968 OMPTraitProperty TIProperty;
969 parseOMPTraitPropertyKind(TIProperty,
Set, TISelector.
Kind, Seen);
971 if (TISelector.
Kind == llvm::omp::TraitSelector::implementation_extension)
974 TIProperty.
Kind = TraitProperty::invalid;
977 if (TIProperty.
Kind == TraitProperty::invalid) {
978 if (PropertyLoc != Tok.getLocation())
979 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
980 << CONTEXT_TRAIT_LVL;
984 if (isValidTraitPropertyForTraitSetAndSelector(TIProperty.
Kind,
993 Diag(PropertyLoc, diag::warn_omp_ctx_incompatible_property_for_selector)
994 << getOpenMPContextTraitPropertyName(TIProperty.
Kind,
996 << getOpenMPContextTraitSelectorName(TISelector.
Kind)
997 << getOpenMPContextTraitSetName(
Set);
998 Diag(PropertyLoc, diag::note_omp_ctx_compatible_set_and_selector_for_property)
999 << getOpenMPContextTraitPropertyName(TIProperty.
Kind,
1001 << getOpenMPContextTraitSelectorName(
1002 getOpenMPContextTraitSelectorForProperty(TIProperty.
Kind))
1003 << getOpenMPContextTraitSetName(
1004 getOpenMPContextTraitSetForProperty(TIProperty.
Kind));
1005 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
1006 << CONTEXT_TRAIT_LVL;
1009void Parser::parseOMPTraitSelectorKind(OMPTraitSelector &TISelector,
1010 llvm::omp::TraitSet
Set,
1011 llvm::StringMap<SourceLocation> &Seen) {
1012 TISelector.
Kind = TraitSelector::invalid;
1014 SourceLocation NameLoc = Tok.getLocation();
1015 StringRef Name = getNameFromIdOrString(*
this, Tok, CONTEXT_SELECTOR_LVL);
1017 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
1018 << CONTEXT_SELECTOR_LVL << listOpenMPContextTraitSelectors(
Set);
1022 TISelector.
Kind = getOpenMPContextTraitSelectorKind(Name,
Set);
1023 if (TISelector.
Kind != TraitSelector::invalid) {
1024 if (checkForDuplicates(*
this, Name, NameLoc, Seen, CONTEXT_SELECTOR_LVL))
1025 TISelector.
Kind = TraitSelector::invalid;
1030 Diag(NameLoc, diag::warn_omp_declare_variant_ctx_not_a_selector)
1031 << Name << getOpenMPContextTraitSetName(
Set);
1033 TraitSet SetForName = getOpenMPContextTraitSetKind(Name);
1034 if (SetForName != TraitSet::invalid) {
1035 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1036 << Name << CONTEXT_SELECTOR_SET_LVL << CONTEXT_SELECTOR_LVL;
1037 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1038 << Name <<
"<selector-name>"
1039 <<
"<property-name>";
1042 for (
const auto &PotentialSet :
1043 {TraitSet::construct, TraitSet::user, TraitSet::implementation,
1044 TraitSet::device, TraitSet::target_device}) {
1045 TraitProperty PropertyForName = getOpenMPContextTraitPropertyKind(
1046 PotentialSet, TraitSelector::invalid, Name);
1047 if (PropertyForName == TraitProperty::invalid)
1049 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1050 << Name << CONTEXT_TRAIT_LVL << CONTEXT_SELECTOR_LVL;
1051 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1052 << getOpenMPContextTraitSetName(
1053 getOpenMPContextTraitSetForProperty(PropertyForName))
1054 << getOpenMPContextTraitSelectorName(
1055 getOpenMPContextTraitSelectorForProperty(PropertyForName))
1056 << (
"(" + Name +
")").str();
1059 Diag(NameLoc, diag::note_omp_declare_variant_ctx_options)
1060 << CONTEXT_SELECTOR_LVL << listOpenMPContextTraitSelectors(
Set);
1067 StringRef SelectorName =
1069 if (SelectorName !=
"score")
1080 <<
"score expression";
1084void Parser::parseOMPContextSelector(
1085 OMPTraitSelector &TISelector, llvm::omp::TraitSet
Set,
1086 llvm::StringMap<SourceLocation> &SeenSelectors) {
1087 unsigned short OuterPC = ParenCount;
1092 auto FinishSelector = [OuterPC,
this]() ->
void {
1095 while (!
SkipUntil({tok::r_brace, tok::r_paren, tok::comma,
1096 tok::annot_pragma_openmp_end},
1099 if (Tok.is(tok::r_paren) && OuterPC > ParenCount)
1100 (void)ConsumeParen();
1101 if (OuterPC <= ParenCount) {
1105 if (!Tok.is(tok::comma) && !Tok.is(tok::r_paren)) {
1111 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
1112 << CONTEXT_SELECTOR_LVL;
1115 SourceLocation SelectorLoc = Tok.getLocation();
1116 parseOMPTraitSelectorKind(TISelector,
Set, SeenSelectors);
1117 if (TISelector.
Kind == TraitSelector::invalid)
1118 return FinishSelector();
1120 bool AllowsTraitScore =
false;
1121 bool RequiresProperty =
false;
1122 if (!isValidTraitSelectorForTraitSet(TISelector.
Kind,
Set, AllowsTraitScore,
1123 RequiresProperty)) {
1124 Diag(SelectorLoc, diag::warn_omp_ctx_incompatible_selector_for_set)
1125 << getOpenMPContextTraitSelectorName(TISelector.
Kind)
1126 << getOpenMPContextTraitSetName(
Set);
1127 Diag(SelectorLoc, diag::note_omp_ctx_compatible_set_for_selector)
1128 << getOpenMPContextTraitSelectorName(TISelector.
Kind)
1129 << getOpenMPContextTraitSetName(
1130 getOpenMPContextTraitSetForSelector(TISelector.
Kind))
1131 << RequiresProperty;
1132 return FinishSelector();
1135 if (!RequiresProperty) {
1137 {getOpenMPContextTraitPropertyForSelector(TISelector.
Kind),
1138 getOpenMPContextTraitSelectorName(TISelector.
Kind)});
1142 if (!Tok.is(tok::l_paren)) {
1143 Diag(SelectorLoc, diag::warn_omp_ctx_selector_without_properties)
1144 << getOpenMPContextTraitSelectorName(TISelector.
Kind)
1145 << getOpenMPContextTraitSetName(
Set);
1146 return FinishSelector();
1149 if (TISelector.
Kind == TraitSelector::user_condition) {
1150 SourceLocation RLoc;
1153 return FinishSelector();
1156 {TraitProperty::user_condition_unknown,
"<condition>"});
1161 tok::annot_pragma_openmp_end);
1163 (void)BDT.consumeOpen();
1165 SourceLocation ScoreLoc = Tok.getLocation();
1168 if (!AllowsTraitScore && !Score.
isUnset()) {
1170 Diag(ScoreLoc, diag::warn_omp_ctx_incompatible_score_for_property)
1171 << getOpenMPContextTraitSelectorName(TISelector.
Kind)
1172 << getOpenMPContextTraitSetName(
Set) << Score.
get();
1174 Diag(ScoreLoc, diag::warn_omp_ctx_incompatible_score_for_property)
1175 << getOpenMPContextTraitSelectorName(TISelector.
Kind)
1176 << getOpenMPContextTraitSetName(
Set) <<
"<invalid>";
1184 llvm::StringMap<SourceLocation> SeenProperties;
1186 parseOMPContextProperty(TISelector,
Set, SeenProperties);
1193void Parser::parseOMPTraitSetKind(OMPTraitSet &TISet,
1194 llvm::StringMap<SourceLocation> &Seen) {
1195 TISet.
Kind = TraitSet::invalid;
1197 SourceLocation NameLoc = Tok.getLocation();
1198 StringRef Name = getNameFromIdOrString(*
this, Tok, CONTEXT_SELECTOR_SET_LVL);
1200 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_options)
1201 << CONTEXT_SELECTOR_SET_LVL << listOpenMPContextTraitSets();
1205 TISet.
Kind = getOpenMPContextTraitSetKind(Name);
1206 if (TISet.
Kind != TraitSet::invalid) {
1207 if (checkForDuplicates(*
this, Name, NameLoc, Seen,
1208 CONTEXT_SELECTOR_SET_LVL))
1209 TISet.
Kind = TraitSet::invalid;
1214 Diag(NameLoc, diag::warn_omp_declare_variant_ctx_not_a_set) << Name;
1216 TraitSelector SelectorForName =
1217 getOpenMPContextTraitSelectorKind(Name, TISet.
Kind);
1218 if (SelectorForName != TraitSelector::invalid) {
1219 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1220 << Name << CONTEXT_SELECTOR_LVL << CONTEXT_SELECTOR_SET_LVL;
1221 bool AllowsTraitScore =
false;
1222 bool RequiresProperty =
false;
1223 isValidTraitSelectorForTraitSet(
1224 SelectorForName, getOpenMPContextTraitSetForSelector(SelectorForName),
1225 AllowsTraitScore, RequiresProperty);
1226 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1227 << getOpenMPContextTraitSetName(
1228 getOpenMPContextTraitSetForSelector(SelectorForName))
1229 << Name << (RequiresProperty ?
"(<property-name>)" :
"");
1232 for (
const auto &PotentialSet :
1233 {TraitSet::construct, TraitSet::user, TraitSet::implementation,
1234 TraitSet::device, TraitSet::target_device}) {
1235 TraitProperty PropertyForName = getOpenMPContextTraitPropertyKind(
1236 PotentialSet, TraitSelector::invalid, Name);
1237 if (PropertyForName == TraitProperty::invalid)
1239 Diag(NameLoc, diag::note_omp_declare_variant_ctx_is_a)
1240 << Name << CONTEXT_TRAIT_LVL << CONTEXT_SELECTOR_SET_LVL;
1241 Diag(NameLoc, diag::note_omp_declare_variant_ctx_try)
1242 << getOpenMPContextTraitSetName(
1243 getOpenMPContextTraitSetForProperty(PropertyForName))
1244 << getOpenMPContextTraitSelectorName(
1245 getOpenMPContextTraitSelectorForProperty(PropertyForName))
1246 << (
"(" + Name +
")").str();
1249 Diag(NameLoc, diag::note_omp_declare_variant_ctx_options)
1250 << CONTEXT_SELECTOR_SET_LVL << listOpenMPContextTraitSets();
1253void Parser::parseOMPContextSelectorSet(
1254 OMPTraitSet &TISet, llvm::StringMap<SourceLocation> &SeenSets) {
1255 auto OuterBC = BraceCount;
1260 auto FinishSelectorSet = [
this, OuterBC]() ->
void {
1263 while (!
SkipUntil({tok::comma, tok::r_brace, tok::r_paren,
1264 tok::annot_pragma_openmp_end},
1267 if (Tok.is(tok::r_brace) && OuterBC > BraceCount)
1268 (void)ConsumeBrace();
1269 if (OuterBC <= BraceCount) {
1273 if (!Tok.is(tok::comma) && !Tok.is(tok::r_brace)) {
1279 Diag(Tok.getLocation(), diag::note_omp_declare_variant_ctx_continue_here)
1280 << CONTEXT_SELECTOR_SET_LVL;
1283 parseOMPTraitSetKind(TISet, SeenSets);
1284 if (TISet.
Kind == TraitSet::invalid)
1285 return FinishSelectorSet();
1289 Diag(Tok.getLocation(), diag::warn_omp_declare_variant_expected)
1291 << (
"context set name \"" + getOpenMPContextTraitSetName(TISet.
Kind) +
1295 if (Tok.is(tok::l_brace)) {
1296 (void)ConsumeBrace();
1298 Diag(Tok.getLocation(), diag::warn_omp_declare_variant_expected)
1300 << (
"'=' that follows the context set name \"" +
1301 getOpenMPContextTraitSetName(TISet.
Kind) +
"\"")
1305 llvm::StringMap<SourceLocation> SeenSelectors;
1307 OMPTraitSelector TISelector;
1308 parseOMPContextSelector(TISelector, TISet.
Kind, SeenSelectors);
1309 if (TISelector.
Kind != TraitSelector::invalid &&
1315 if (Tok.is(tok::r_brace)) {
1316 (void)ConsumeBrace();
1318 Diag(Tok.getLocation(), diag::warn_omp_declare_variant_expected)
1320 << (
"context selectors for the context set \"" +
1321 getOpenMPContextTraitSetName(TISet.
Kind) +
"\"")
1326bool Parser::parseOMPContextSelectors(
SourceLocation Loc, OMPTraitInfo &TI) {
1327 llvm::StringMap<SourceLocation> SeenSets;
1330 parseOMPContextSelectorSet(TISet, SeenSets);
1331 if (TISet.
Kind != TraitSet::invalid && !TISet.
Selectors.empty())
1332 TI.
Sets.push_back(TISet);
1341 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
1342 PP.EnterToken(Tok,
true);
1343 PP.EnterTokenStream(Toks,
true,
1349 FNContextRAII FnContext(*
this, Ptr);
1351 SourceLocation RLoc;
1361 getOpenMPDirectiveName(OMPD_declare_variant, OMPVersion), RLoc,
1364 if (!AssociatedFunction.
isUsable()) {
1365 if (!Tok.is(tok::annot_pragma_openmp_end))
1369 (void)ConsumeAnnotationToken();
1373 OMPTraitInfo *ParentTI =
1374 Actions.OpenMP().getOMPTraitInfoForSurroundingScope();
1375 ASTContext &ASTCtx = Actions.getASTContext();
1377 SmallVector<OMPAdjustArgsDescriptor *, 3> AdjustArgs;
1378 SmallVector<OMPInteropInfo, 3> AppendArgs;
1379 SourceLocation AdjustArgsLoc, AppendArgsLoc;
1382 if (Tok.is(tok::annot_pragma_openmp_end)) {
1383 Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause)
1387 bool IsError =
false;
1388 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1391 : getOpenMPClauseKind(PP.getSpelling(Tok));
1392 if (!isAllowedClauseForDirective(OMPD_declare_variant, CKind, OMPVersion)) {
1393 Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause)
1394 << (OMPVersion < 51 ? 0 : 1);
1400 IsError = parseOMPDeclareVariantMatchClause(Loc, TI, ParentTI);
1402 case OMPC_adjust_args: {
1403 AdjustArgsLoc = Tok.getLocation();
1405 SemaOpenMP::OpenMPVarListDataTy
Data;
1406 SmallVector<Expr *> Vars;
1407 SmallVector<OMPAdjustArgsItem, 4> Items;
1411 for (Expr *E : Vars) {
1412 OMPAdjustArgsItem Item;
1414 Items.push_back(Item);
1420 if (
Data.NeedDevicePtrModifierLoc.isValid())
1422 Data.NeedDevicePtrModifier);
1423 OMPAdjustArgsDescriptor *Desc =
1424 Actions.OpenMP().ActOnOpenMPAdjustArgsClause(
1425 AdjustOp, NeedDevicePtrModifier, Items, AdjustArgsLoc);
1427 AdjustArgs.push_back(Desc);
1433 case OMPC_append_args:
1434 if (!AppendArgs.empty()) {
1435 Diag(AppendArgsLoc, diag::err_omp_more_one_clause)
1436 << getOpenMPDirectiveName(OMPD_declare_variant, OMPVersion)
1437 << getOpenMPClauseName(CKind) << 0;
1441 AppendArgsLoc = Tok.getLocation();
1443 IsError = parseOpenMPAppendArgs(AppendArgs);
1447 llvm_unreachable(
"Unexpected clause for declare variant.");
1454 (void)ConsumeAnnotationToken();
1458 if (Tok.is(tok::comma))
1462 std::optional<std::pair<FunctionDecl *, Expr *>> DeclVarData =
1463 Actions.OpenMP().checkOpenMPDeclareVariantFunction(
1464 Ptr, AssociatedFunction.
get(), TI, AppendArgs.size(),
1465 SourceRange(Loc, Tok.getLocation()));
1467 if (DeclVarData && !TI.
Sets.empty())
1468 Actions.OpenMP().ActOnOpenMPDeclareVariantDirective(
1469 DeclVarData->first, DeclVarData->second, TI, AdjustArgs, AppendArgs,
1470 AdjustArgsLoc, AppendArgsLoc, SourceRange(Loc, Tok.getLocation()));
1473 (void)ConsumeAnnotationToken();
1476bool Parser::parseOpenMPAppendArgs(
1478 bool HasError =
false;
1481 if (
T.expectAndConsume(diag::err_expected_lparen_after,
1482 getOpenMPClauseName(OMPC_append_args).data()))
1487 while (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->isStr(
"interop")) {
1490 tok::annot_pragma_openmp_end);
1491 if (IT.expectAndConsume(diag::err_expected_lparen_after,
"interop"))
1494 OMPInteropInfo InteropInfo;
1495 if (ParseOMPInteropInfo(InteropInfo, OMPC_append_args))
1498 InteropInfos.push_back(InteropInfo);
1501 if (Tok.is(tok::comma))
1504 if (!HasError && InteropInfos.empty()) {
1506 Diag(Tok.getLocation(), diag::err_omp_unexpected_append_op);
1507 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
1510 HasError =
T.consumeClose() || HasError;
1514bool Parser::parseOMPDeclareVariantMatchClause(
SourceLocation Loc,
1516 OMPTraitInfo *ParentTI) {
1520 : getOpenMPClauseKind(PP.getSpelling(Tok));
1521 if (CKind != OMPC_match) {
1522 Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause)
1529 if (
T.expectAndConsume(diag::err_expected_lparen_after,
1530 getOpenMPClauseName(OMPC_match).data()))
1534 parseOMPContextSelectors(Loc, TI);
1537 (void)
T.consumeClose();
1547 for (
const OMPTraitSet &ParentSet : ParentTI->
Sets) {
1548 bool MergedSet =
false;
1549 for (OMPTraitSet &
Set : TI.
Sets) {
1550 if (
Set.Kind != ParentSet.
Kind)
1553 for (
const OMPTraitSelector &ParentSelector : ParentSet.
Selectors) {
1554 bool MergedSelector =
false;
1555 for (OMPTraitSelector &Selector :
Set.Selectors) {
1556 if (Selector.
Kind != ParentSelector.
Kind)
1558 MergedSelector =
true;
1559 for (
const OMPTraitProperty &ParentProperty :
1561 bool MergedProperty =
false;
1575 if (Selector.
Kind == llvm::omp::TraitSelector::user_condition) {
1576 Diag(Loc, diag::err_omp_declare_variant_nested_user_condition);
1579 Diag(Loc, diag::err_omp_declare_variant_duplicate_nested_trait)
1580 << getOpenMPContextTraitPropertyName(
1582 << getOpenMPContextTraitSelectorName(ParentSelector.
Kind)
1583 << getOpenMPContextTraitSetName(ParentSet.
Kind);
1586 if (!MergedProperty)
1587 Selector.
Properties.push_back(ParentProperty);
1590 if (!MergedSelector)
1591 Set.Selectors.push_back(ParentSelector);
1595 TI.
Sets.push_back(ParentSet);
1604 std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
1605 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1608 : getOpenMPClauseKind(PP.getSpelling(Tok));
1609 if (DKind == OMPD_depobj && CKind == OMPC_update)
1610 CKind = OMPC_update_depend_objects;
1611 Actions.OpenMP().StartOpenMPClause(CKind);
1613 ParseOpenMPClause(DKind, CKind, !SeenClauses[
unsigned(CKind)]);
1614 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
1616 SeenClauses[
unsigned(CKind)] =
true;
1617 if (Clause !=
nullptr)
1618 Clauses.push_back(Clause);
1619 if (Tok.is(tok::annot_pragma_openmp_end)) {
1620 Actions.OpenMP().EndOpenMPClause();
1624 if (Tok.is(tok::comma))
1626 Actions.OpenMP().EndOpenMPClause();
1632 SmallVector<std::string, 4> Assumptions;
1633 bool SkippedClauses =
false;
1635 auto SkipBraces = [&](llvm::StringRef Spelling,
bool IssueNote) {
1637 tok::annot_pragma_openmp_end);
1638 if (
T.expectAndConsume(diag::err_expected_lparen_after, Spelling.data()))
1641 if (IssueNote &&
T.getCloseLocation().isValid())
1642 Diag(
T.getCloseLocation(),
1643 diag::note_omp_assumption_clause_continue_here);
1649 auto MatchACMClause = [&](StringRef RawString) {
1650 llvm::StringSwitch<int> SS(RawString);
1651 unsigned ACMIdx = 0;
1652 for (
const AssumptionClauseMappingInfo &ACMI : AssumptionClauseMappings) {
1653 if (ACMI.StartsWith)
1654 SS.StartsWith(ACMI.Identifier, ACMIdx++);
1656 SS.Case(ACMI.Identifier, ACMIdx++);
1658 return SS.Default(-1);
1661 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1662 IdentifierInfo *II =
nullptr;
1663 SourceLocation StartLoc = Tok.getLocation();
1665 if (Tok.isAnyIdentifier()) {
1666 II = Tok.getIdentifierInfo();
1667 Idx = MatchACMClause(II->
getName());
1671 bool NextIsLPar = Tok.is(tok::l_paren);
1674 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
1675 Diag(StartLoc, diag::warn_omp_unknown_assumption_clause_missing_id)
1676 << llvm::omp::getOpenMPDirectiveName(DKind, OMPVersion)
1677 << llvm::omp::getAllAssumeClauseOptions() << NextIsLPar;
1679 SkipBraces(II ? II->
getName() :
"",
true);
1680 SkippedClauses =
true;
1683 const AssumptionClauseMappingInfo &ACMI = AssumptionClauseMappings[Idx];
1684 if (ACMI.HasDirectiveList || ACMI.HasExpression) {
1687 SkippedClauses =
true;
1688 SkipBraces(II->
getName(),
false);
1693 Diag(Tok.getLocation(),
1694 diag::warn_omp_unknown_assumption_clause_without_args)
1696 SkipBraces(II->
getName(),
true);
1699 assert(II &&
"Expected an identifier clause!");
1700 std::string Assumption = II->
getName().str();
1701 if (ACMI.StartsWith)
1702 Assumption =
"ompx_" + Assumption.substr(ACMI.Identifier.size());
1704 Assumption =
"omp_" + Assumption;
1705 Assumptions.push_back(Assumption);
1708 Actions.OpenMP().ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions,
1713 if (Actions.OpenMP().isInOpenMPAssumeScope())
1714 Actions.OpenMP().ActOnOpenMPEndAssumesDirective();
1716 Diag(Loc, diag::err_expected_begin_assumes);
1730struct SimpleClauseData {
1733 SourceLocation LOpen;
1734 SourceLocation TypeLoc;
1735 SourceLocation RLoc;
1736 SimpleClauseData(
unsigned Type, SourceLocation Loc, SourceLocation LOpen,
1737 SourceLocation TypeLoc, SourceLocation RLoc)
1738 :
Type(
Type), Loc(Loc), LOpen(LOpen), TypeLoc(TypeLoc), RLoc(RLoc) {}
1742static std::optional<SimpleClauseData>
1749 if (
T.expectAndConsume(diag::err_expected_lparen_after,
1750 getOpenMPClauseName(Kind).data()))
1751 return std::nullopt;
1757 if (
Tok.isNot(tok::r_paren) &&
Tok.isNot(tok::comma) &&
1758 Tok.isNot(tok::annot_pragma_openmp_end))
1763 if (!
T.consumeClose())
1764 RLoc =
T.getCloseLocation();
1766 return SimpleClauseData(
Type, Loc, LOpen,
TypeLoc, RLoc);
1769void Parser::ParseOMPDeclareTargetClauses(
1771 SourceLocation DeviceTypeLoc;
1772 bool RequiresToLinkLocalOrIndirectClause =
false;
1773 bool HasToLinkLocalOrIndirectClause =
false;
1774 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
1775 OMPDeclareTargetDeclAttr::MapTypeTy MT = OMPDeclareTargetDeclAttr::MT_To;
1776 bool HasIdentifier = Tok.is(tok::identifier);
1777 if (HasIdentifier) {
1779 RequiresToLinkLocalOrIndirectClause =
true;
1780 IdentifierInfo *II = Tok.getIdentifierInfo();
1781 StringRef ClauseName = II->
getName();
1782 bool IsDeviceTypeClause =
1784 getOpenMPClauseKind(ClauseName) == OMPC_device_type;
1786 bool IsIndirectClause =
getLangOpts().OpenMP >= 51 &&
1787 getOpenMPClauseKind(ClauseName) == OMPC_indirect;
1789 if (DTCI.
Indirect && IsIndirectClause) {
1790 llvm::omp::Version OMPVersion =
1791 Actions.getLangOpts().getOpenMPVersion();
1792 Diag(Tok, diag::err_omp_more_one_clause)
1793 << getOpenMPDirectiveName(OMPD_declare_target, OMPVersion)
1794 << getOpenMPClauseName(OMPC_indirect) << 0;
1797 bool IsToEnterLinkOrLocalClause =
1798 OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, MT);
1799 assert((!IsDeviceTypeClause || !IsToEnterLinkOrLocalClause) &&
1804 if (
getLangOpts().OpenMP >= 52 && ClauseName ==
"to") {
1805 Diag(Tok, diag::err_omp_declare_target_unexpected_to_clause);
1808 if (
getLangOpts().OpenMP <= 51 && ClauseName ==
"enter") {
1809 Diag(Tok, diag::err_omp_declare_target_unexpected_enter_clause);
1814 if (
getLangOpts().OpenMP < 60 && ClauseName ==
"local") {
1816 ? diag::err_omp_declare_target_unexpected_clause_52
1817 : diag::err_omp_declare_target_unexpected_clause)
1825 if (!IsDeviceTypeClause && !IsIndirectClause &&
1826 DTCI.
Kind == OMPD_begin_declare_target) {
1828 ? diag::err_omp_declare_target_unexpected_clause_52
1829 : diag::err_omp_declare_target_unexpected_clause)
1830 << ClauseName << (
getLangOpts().OpenMP >= 51 ? 3 : 0);
1834 if (!IsDeviceTypeClause && !IsToEnterLinkOrLocalClause &&
1835 !IsIndirectClause) {
1837 ? diag::err_omp_declare_target_unexpected_clause_52
1838 : diag::err_omp_declare_target_unexpected_clause)
1847 if (IsToEnterLinkOrLocalClause || IsIndirectClause)
1848 HasToLinkLocalOrIndirectClause =
true;
1850 if (IsIndirectClause) {
1851 if (!ParseOpenMPIndirectClause(DTCI,
false))
1856 if (IsDeviceTypeClause) {
1857 std::optional<SimpleClauseData> DevTypeData =
1860 if (DeviceTypeLoc.
isValid()) {
1862 Diag(DevTypeData->Loc,
1863 diag::warn_omp_more_one_device_type_clause);
1867 case OMPC_DEVICE_TYPE_any:
1868 DTCI.
DT = OMPDeclareTargetDeclAttr::DT_Any;
1870 case OMPC_DEVICE_TYPE_host:
1871 DTCI.
DT = OMPDeclareTargetDeclAttr::DT_Host;
1873 case OMPC_DEVICE_TYPE_nohost:
1874 DTCI.
DT = OMPDeclareTargetDeclAttr::DT_NoHost;
1877 llvm_unreachable(
"Unexpected device_type");
1879 DeviceTypeLoc = DevTypeData->Loc;
1886 if (DTCI.
Kind == OMPD_declare_target || HasIdentifier) {
1887 auto &&
Callback = [
this, MT, &DTCI](CXXScopeSpec &SS,
1888 DeclarationNameInfo NameInfo) {
1889 NamedDecl *ND = Actions.OpenMP().lookupOpenMPDeclareTargetName(
1893 SemaOpenMP::DeclareTargetContextInfo::MapInfo MI{MT, NameInfo.
getLoc()};
1896 Diag(NameInfo.
getLoc(), diag::err_omp_declare_target_multiple)
1899 if (ParseOpenMPSimpleVarList(OMPD_declare_target,
Callback,
1904 if (Tok.is(tok::l_paren)) {
1906 diag::err_omp_begin_declare_target_unexpected_implicit_to_clause);
1909 if (!HasIdentifier && Tok.isNot(tok::annot_pragma_openmp_end)) {
1912 ? diag::err_omp_declare_target_wrong_clause_after_implicit_enter
1913 : diag::err_omp_declare_target_wrong_clause_after_implicit_to);
1918 if (Tok.is(tok::comma))
1922 if (DTCI.
Indirect && DTCI.
DT != OMPDeclareTargetDeclAttr::DT_Any)
1923 Diag(DeviceTypeLoc, diag::err_omp_declare_target_indirect_device_type);
1926 if (DTCI.
Kind == OMPD_declare_target && RequiresToLinkLocalOrIndirectClause &&
1927 !HasToLinkLocalOrIndirectClause)
1928 Diag(DTCI.
Loc, diag::err_omp_declare_target_missing_required_clause)
1940 if (Tok.is(tok::annot_pragma_openmp_end))
1943 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
1944 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
1945 << getOpenMPDirectiveName(DKind, OMPVersion);
1946 while (Tok.isNot(tok::annot_pragma_openmp_end))
1955 bool SkipUntilOpenMPEnd) {
1956 int DiagSelection = ExpectedKind == OMPD_end_declare_target ? 0 : 1;
1958 if (FoundKind == ExpectedKind) {
1960 skipUntilPragmaOpenMPEnd(ExpectedKind);
1964 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
1965 Diag(FoundLoc, diag::err_expected_end_declare_target_or_variant)
1967 Diag(BeginLoc, diag::note_matching)
1968 << (
"'#pragma omp " + getOpenMPDirectiveName(BeginKind, OMPVersion) +
"'")
1970 if (SkipUntilOpenMPEnd)
1977 parseOMPEndDirective(BeginDKind, OMPD_end_declare_target, EndDKind, DKLoc,
1981 if (Tok.is(tok::annot_pragma_openmp_end))
1982 ConsumeAnnotationToken();
1988 assert(Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp) &&
1989 "Not an OpenMP directive!");
1992 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
1997 TentativeParsingAction TPA(*
this);
1998 Loc = ConsumeAnnotationToken();
2000 if (DKind == OMPD_declare_reduction || DKind == OMPD_declare_mapper) {
2005 Toks.push_back(Tok);
2006 while (Cnt && Tok.isNot(tok::eof)) {
2008 if (Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp))
2010 else if (Tok.is(tok::annot_pragma_openmp_end))
2012 Toks.push_back(Tok);
2017 auto *LP =
new LateParsedPragma(
this, AS);
2019 getCurrentClass().LateParsedDeclarations.push_back(LP);
2024 Loc = ConsumeAnnotationToken();
2029 case OMPD_threadprivate: {
2031 DeclDirectiveListParserHelper Helper(
this, DKind);
2032 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2034 skipUntilPragmaOpenMPEnd(DKind);
2036 ConsumeAnnotationToken();
2037 return Actions.OpenMP().ActOnOpenMPThreadprivateDirective(
2038 Loc, Helper.getIdentifiers());
2042 case OMPD_groupprivate: {
2044 DeclDirectiveListParserHelper Helper(
this, DKind);
2045 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2047 skipUntilPragmaOpenMPEnd(DKind);
2049 ConsumeAnnotationToken();
2050 return Actions.OpenMP().ActOnOpenMPGroupPrivateDirective(
2051 Loc, Helper.getIdentifiers());
2055 case OMPD_allocate: {
2057 DeclDirectiveListParserHelper Helper(
this, DKind);
2058 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2060 SmallVector<OMPClause *, 1> Clauses;
2061 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
2062 std::bitset<llvm::omp::Clause_enumSize + 1> SeenClauses;
2063 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2065 Tok.isAnnotation() ? OMPC_unknown
2066 : getOpenMPClauseKind(PP.getSpelling(Tok));
2067 Actions.OpenMP().StartOpenMPClause(CKind);
2068 OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind,
2069 !SeenClauses[
unsigned(CKind)]);
2070 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
2072 SeenClauses[
unsigned(CKind)] =
true;
2073 if (Clause !=
nullptr)
2074 Clauses.push_back(Clause);
2075 if (Tok.is(tok::annot_pragma_openmp_end)) {
2076 Actions.OpenMP().EndOpenMPClause();
2080 if (Tok.is(tok::comma))
2082 Actions.OpenMP().EndOpenMPClause();
2084 skipUntilPragmaOpenMPEnd(DKind);
2087 ConsumeAnnotationToken();
2088 return Actions.OpenMP().ActOnOpenMPAllocateDirective(
2089 Loc, Helper.getIdentifiers(), Clauses);
2093 case OMPD_requires: {
2095 SmallVector<OMPClause *, 5> Clauses;
2096 llvm::SmallBitVector SeenClauses(llvm::omp::Clause_enumSize + 1);
2097 if (Tok.is(tok::annot_pragma_openmp_end)) {
2098 Diag(Tok, diag::err_omp_expected_clause)
2099 << getOpenMPDirectiveName(OMPD_requires, OMPVersion);
2102 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2105 : getOpenMPClauseKind(PP.getSpelling(Tok));
2106 Actions.OpenMP().StartOpenMPClause(CKind);
2107 OMPClause *Clause = ParseOpenMPClause(OMPD_requires, CKind,
2108 !SeenClauses[
unsigned(CKind)]);
2109 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
2111 SeenClauses[
unsigned(CKind)] =
true;
2112 if (Clause !=
nullptr)
2113 Clauses.push_back(Clause);
2114 if (Tok.is(tok::annot_pragma_openmp_end)) {
2115 Actions.OpenMP().EndOpenMPClause();
2119 if (Tok.is(tok::comma))
2121 Actions.OpenMP().EndOpenMPClause();
2124 if (Clauses.empty()) {
2125 Diag(Tok, diag::err_omp_expected_clause)
2126 << getOpenMPDirectiveName(OMPD_requires, OMPVersion);
2127 ConsumeAnnotationToken();
2130 ConsumeAnnotationToken();
2131 return Actions.OpenMP().ActOnOpenMPRequiresDirective(StartLoc, Clauses);
2134 SmallVector<OMPClause *, 1> Clauses;
2136 ParseOpenMPClauses(DKind, Clauses, StartLoc);
2137 Actions.OpenMP().ActOnOpenMPErrorDirective(Clauses, StartLoc,
2143 case OMPD_begin_assumes:
2146 case OMPD_end_assumes:
2149 case OMPD_declare_reduction:
2151 if (
DeclGroupPtrTy Res = ParseOpenMPDeclareReductionDirective(AS)) {
2152 skipUntilPragmaOpenMPEnd(OMPD_declare_reduction);
2154 ConsumeAnnotationToken();
2158 case OMPD_declare_mapper: {
2160 if (
DeclGroupPtrTy Res = ParseOpenMPDeclareMapperDirective(AS)) {
2162 ConsumeAnnotationToken();
2167 case OMPD_begin_declare_variant: {
2172 ConsumeAnnotationToken();
2176 case OMPD_end_declare_variant: {
2178 if (Actions.OpenMP().isInOpenMPDeclareVariantScope())
2179 Actions.OpenMP().ActOnOpenMPEndDeclareVariant();
2181 Diag(Loc, diag::err_expected_begin_declare_variant);
2183 ConsumeAnnotationToken();
2186 case OMPD_declare_variant:
2187 case OMPD_declare_simd: {
2193 Toks.push_back(Tok);
2195 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2196 Toks.push_back(Tok);
2199 Toks.push_back(Tok);
2203 if (Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp)) {
2204 Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, Delayed,
2206 }
else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
2210 ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
2211 MaybeParseCXX11Attributes(Attrs);
2212 ParsingDeclSpec PDS(*
this);
2213 Ptr = ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs, &PDS);
2216 ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
2220 Diag(Loc, diag::err_omp_decl_in_declare_simd_variant)
2221 << (DKind == OMPD_declare_simd ? 0 : 1);
2225 DeclGroupRef DG =
Ptr.get();
2226 SourceManager &SM = PP.getSourceManager();
2227 if (llvm::none_of(DG, [&](
const Decl *D) {
2230 Diag(Loc, diag::err_omp_decl_in_declare_simd_variant)
2231 << (DKind == OMPD_declare_simd ? 0 : 1);
2235 if (DKind == OMPD_declare_simd)
2236 return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc);
2237 assert(DKind == OMPD_declare_variant &&
2238 "Expected declare variant directive only");
2239 ParseOMPDeclareVariantClauses(Ptr, Toks, Loc);
2242 case OMPD_begin_declare_target:
2243 case OMPD_declare_target: {
2245 bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
2246 SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
2247 if (DKind == OMPD_declare_target && !HasClauses &&
2249 Diag(DTLoc, diag::warn_omp_deprecated_declare_target_delimited_form);
2251 ParseOMPDeclareTargetClauses(DTCI);
2252 bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||
2259 if (HasImplicitMappings) {
2260 Actions.OpenMP().ActOnStartOpenMPDeclareTargetContext(DTCI);
2264 Actions.OpenMP().ActOnFinishedOpenMPDeclareTargetContext(DTCI);
2265 llvm::SmallVector<Decl *, 4> Decls;
2267 Decls.push_back(It.first);
2268 return Actions.BuildDeclaratorGroup(Decls);
2270 case OMPD_end_declare_target: {
2271 if (!Actions.OpenMP().isInOpenMPDeclareTargetContext()) {
2272 Diag(Tok, diag::err_omp_unexpected_directive)
2273 << 1 << getOpenMPDirectiveName(DKind, OMPVersion);
2276 const SemaOpenMP::DeclareTargetContextInfo &DTCI =
2277 Actions.OpenMP().ActOnOpenMPEndDeclareTargetDirective();
2278 ParseOMPEndDeclareTargetDirective(DTCI.
Kind, DKind, DTCI.
Loc);
2282 Diag(Tok, diag::err_omp_unexpected_directive)
2283 << 1 << getOpenMPDirectiveName(DKind, OMPVersion);
2287 Diag(Tok, diag::err_omp_unknown_directive);
2290 switch (getDirectiveCategory(DKind)) {
2291 case Category::Executable:
2292 case Category::Meta:
2293 case Category::Subsidiary:
2294 case Category::Utility:
2295 Diag(Tok, diag::err_omp_unexpected_directive)
2296 << 1 << getOpenMPDirectiveName(DKind, OMPVersion);
2298 case Category::Declarative:
2299 case Category::Informational:
2303 while (Tok.isNot(tok::annot_pragma_openmp_end))
2309StmtResult Parser::ParseOpenMPExecutableDirective(
2311 bool ReadDirectiveWithinMetadirective) {
2313 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
2315 bool HasAssociatedStatement =
true;
2316 Association Assoc = getDirectiveAssociation(DKind);
2320 if (DKind != OMPD_ordered_standalone && DKind != OMPD_section &&
2321 (Assoc == Association::None || Assoc == Association::Separating)) {
2322 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2323 ParsedStmtContext()) {
2324 Diag(Tok, diag::err_omp_immediate_directive)
2325 << getOpenMPDirectiveName(DKind, OMPVersion) << 0;
2326 if (DKind == OMPD_error) {
2327 SkipUntil(tok::annot_pragma_openmp_end);
2331 HasAssociatedStatement =
false;
2334 SourceLocation EndLoc;
2335 SmallVector<OMPClause *, 5> Clauses;
2336 llvm::SmallBitVector SeenClauses(llvm::omp::Clause_enumSize + 1);
2337 DeclarationNameInfo DirName;
2344 bool ImplicitClauseAllowed =
false;
2345 if (DKind == OMPD_flush || DKind == OMPD_depobj) {
2347 ImplicitClauseAllowed =
true;
2351 if (DKind == OMPD_critical) {
2353 tok::annot_pragma_openmp_end);
2354 if (!
T.consumeOpen()) {
2355 if (Tok.isAnyIdentifier()) {
2357 DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation());
2360 Diag(Tok, diag::err_omp_expected_identifier_for_critical);
2364 }
else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) {
2366 if (Tok.isNot(tok::annot_pragma_openmp_end))
2374 ParseScope OMPDirectiveScope(
this, ScopeFlags);
2375 Actions.OpenMP().StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(),
2378 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2381 if (ReadDirectiveWithinMetadirective && Tok.is(tok::r_paren)) {
2382 while (Tok.isNot(tok::annot_pragma_openmp_end))
2386 bool HasImplicitClause =
false;
2387 if (ImplicitClauseAllowed && Tok.is(tok::l_paren)) {
2388 HasImplicitClause =
true;
2391 PP.EnterToken(Tok,
true);
2392 PP.EnterToken(ImplicitTok,
true);
2397 : getOpenMPClauseKind(PP.getSpelling(Tok));
2398 if (DKind == OMPD_depobj && CKind == OMPC_update)
2399 CKind = OMPC_update_depend_objects;
2401 if (HasImplicitClause) {
2402 assert(CKind == OMPC_unknown &&
"Must be unknown implicit clause.");
2403 if (DKind == OMPD_flush) {
2406 assert(DKind == OMPD_depobj &&
"Expected flush or depobj directives.");
2407 CKind = OMPC_depobj;
2411 ImplicitClauseAllowed =
false;
2412 Actions.OpenMP().StartOpenMPClause(CKind);
2413 HasImplicitClause =
false;
2414 SourceLocation ClauseLoc = Tok.getLocation();
2417 ParseOpenMPClause(DKind, CKind, !SeenClauses[
unsigned(CKind)]);
2418 SeenClauses[
unsigned(CKind)] =
true;
2420 Clauses.push_back(Clause);
2423 if (Tok.is(tok::comma))
2425 Actions.OpenMP().EndOpenMPClause();
2429 if (Tok.getLocation() == ClauseLoc) {
2430 skipUntilPragmaOpenMPEnd(DKind);
2435 EndLoc = Tok.getLocation();
2437 ConsumeAnnotationToken();
2439 assert(DKind != OMPD_ordered_blockassoc &&
2440 "Wrong kind for ordered directive");
2441 if (DKind == OMPD_ordered_standalone) {
2444 for (
auto CK : {OMPC_depend, OMPC_doacross}) {
2445 if (SeenClauses[
unsigned(CK)]) {
2446 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2447 ParsedStmtContext()) {
2448 Diag(Loc, diag::err_omp_immediate_directive)
2449 << getOpenMPDirectiveName(DKind, OMPVersion) << 1
2450 << getOpenMPClauseName(CK);
2452 HasAssociatedStatement =
false;
2456 if (HasAssociatedStatement)
2457 DKind = OMPD_ordered_blockassoc;
2460 if ((DKind == OMPD_tile || DKind == OMPD_stripe) &&
2461 !SeenClauses[
unsigned(OMPC_sizes)]) {
2462 Diag(Loc, diag::err_omp_required_clause)
2463 << getOpenMPDirectiveName(DKind, OMPVersion) <<
"sizes";
2465 if (DKind == OMPD_split && !SeenClauses[
unsigned(OMPC_counts)]) {
2466 Diag(Loc, diag::err_omp_required_clause)
2467 << getOpenMPDirectiveName(DKind, OMPVersion) <<
"counts";
2471 if (HasAssociatedStatement) {
2473 Actions.OpenMP().ActOnOpenMPRegionStart(DKind,
getCurScope());
2479 Sema::CompoundScopeRAII Scope(Actions);
2480 AssociatedStmt = ParseStatement();
2485 Actions.OpenMP().ActOnOpenMPLoopnest(AssociatedStmt.get());
2488 Actions.OpenMP().ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
2489 }
else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data ||
2490 DKind == OMPD_target_exit_data) {
2491 Actions.OpenMP().ActOnOpenMPRegionStart(DKind,
getCurScope());
2492 AssociatedStmt = (Sema::CompoundScopeRAII(Actions),
2493 Actions.ActOnCompoundStmt(Loc, Loc, {},
2496 Actions.OpenMP().ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
2500 DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, EndLoc);
2503 Actions.OpenMP().EndOpenMPDSABlock(
Directive.get());
2504 OMPDirectiveScope.Exit();
2509StmtResult Parser::ParseOpenMPInformationalDirective(
2511 bool ReadDirectiveWithinMetadirective) {
2513 "Unexpected directive category");
2515 bool HasAssociatedStatement =
true;
2517 SmallVector<OMPClause *, 5> Clauses;
2518 llvm::SmallBitVector SeenClauses(llvm::omp::Clause_enumSize + 1);
2519 DeclarationNameInfo DirName;
2522 ParseScope OMPDirectiveScope(
this, ScopeFlags);
2524 Actions.OpenMP().StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(),
2527 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2528 if (ReadDirectiveWithinMetadirective && Tok.is(tok::r_paren)) {
2529 while (Tok.isNot(tok::annot_pragma_openmp_end))
2536 : getOpenMPClauseKind(PP.getSpelling(Tok));
2537 Actions.OpenMP().StartOpenMPClause(CKind);
2539 ParseOpenMPClause(DKind, CKind, !SeenClauses[
unsigned(CKind)]);
2540 SeenClauses[
unsigned(CKind)] =
true;
2542 Clauses.push_back(Clause);
2544 if (Tok.is(tok::comma))
2546 Actions.OpenMP().EndOpenMPClause();
2549 SourceLocation EndLoc = Tok.getLocation();
2550 ConsumeAnnotationToken();
2553 if (HasAssociatedStatement) {
2554 Actions.OpenMP().ActOnOpenMPRegionStart(DKind,
getCurScope());
2557 Sema::CompoundScopeRAII Scope(Actions);
2558 AssociatedStmt = ParseStatement();
2561 Actions.OpenMP().ActOnOpenMPRegionEnd(AssociatedStmt, Clauses);
2565 DKind, DirName, Clauses, AssociatedStmt.get(), Loc, EndLoc);
2567 Actions.OpenMP().EndOpenMPDSABlock(
Directive.get());
2568 OMPDirectiveScope.Exit();
2573StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
2574 ParsedStmtContext StmtCtx,
bool ReadDirectiveWithinMetadirective) {
2575 if (!ReadDirectiveWithinMetadirective)
2576 assert(Tok.isOneOf(tok::annot_pragma_openmp, tok::annot_attr_openmp) &&
2577 "Not an OpenMP directive!");
2580 SourceLocation Loc = ReadDirectiveWithinMetadirective
2582 : ConsumeAnnotationToken();
2583 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
2585 if (ReadDirectiveWithinMetadirective && DKind == OMPD_unknown) {
2586 Diag(Tok, diag::err_omp_unknown_directive);
2592 bool IsExecutable = [&]() {
2593 if (DKind == OMPD_error)
2595 auto Res = getDirectiveCategory(DKind);
2596 return Res == Category::Executable || Res == Category::Subsidiary;
2600 Directive = ParseOpenMPExecutableDirective(
2601 StmtCtx, DKind, Loc, ReadDirectiveWithinMetadirective);
2602 assert(!
Directive.isUnset() &&
"Executable directive remained unprocessed");
2611 if (ReadDirectiveWithinMetadirective && Tok.is(tok::r_paren))
2612 while (Tok.isNot(tok::annot_pragma_openmp_end))
2615 skipUntilPragmaOpenMPEnd(DKind);
2616 if (Tok.is(tok::annot_pragma_openmp_end))
2617 ConsumeAnnotationToken();
2620 case OMPD_metadirective: {
2622 SmallVector<VariantMatchInfo, 4> VMIs;
2623 SmallVector<OMPTraitInfo *, 4> TraitInfos;
2628 TentativeParsingAction TPA(*
this);
2629 ASTContext &ASTContext = Actions.getASTContext();
2632 tok::annot_pragma_openmp_end);
2633 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2636 : getOpenMPClauseKind(PP.getSpelling(Tok));
2638 if (CKind == OMPC_unknown) {
2639 Diag(Tok, diag::err_omp_expected_clause) <<
"metadirective";
2641 SkipUntil(tok::annot_pragma_openmp_end);
2644 if (
getLangOpts().OpenMP < 52 && CKind == OMPC_otherwise)
2645 Diag(Tok, diag::err_omp_unexpected_clause)
2646 << getOpenMPClauseName(CKind) <<
"metadirective";
2647 if (CKind == OMPC_default &&
getLangOpts().OpenMP >= 52)
2648 Diag(Tok, diag::warn_omp_default_deprecated);
2653 if (
T.expectAndConsume(diag::err_expected_lparen_after,
2654 getOpenMPClauseName(CKind).data())) {
2656 SkipUntil(tok::annot_pragma_openmp_end);
2660 OMPTraitInfo &TI = Actions.getASTContext().getNewOMPTraitInfo();
2661 if (CKind == OMPC_when) {
2663 parseOMPContextSelectors(Loc, TI);
2664 if (TI.
Sets.size() == 0) {
2665 Diag(Tok, diag::err_omp_expected_context_selector) <<
"when clause";
2671 if (Tok.is(tok::colon))
2674 Diag(Tok, diag::err_omp_expected_colon) <<
"when clause";
2682 while (Tok.isNot(tok::r_paren) || paren != 0) {
2683 if (Tok.is(tok::l_paren))
2685 if (Tok.is(tok::r_paren))
2687 if (Tok.is(tok::annot_pragma_openmp_end)) {
2688 Diag(Tok, diag::err_omp_expected_punc)
2689 << getOpenMPClauseName(CKind) << 0;
2696 if (Tok.is(tok::r_paren))
2699 VariantMatchInfo VMI;
2702 VMIs.push_back(VMI);
2703 TraitInfos.push_back(&TI);
2706 SourceLocation EndLoc = Tok.getLocation();
2711 [
this, Loc](StringRef ISATrait) {
2714 Diag(Loc, diag::warn_unknown_declare_variant_isa_trait) << ISATrait;
2716 TargetOMPContext OMPCtx(ASTContext, std::move(DiagUnknownTrait),
2718 ArrayRef<llvm::omp::TraitProperty>(),
2719 Actions.OpenMP().getOpenMPDeviceNum());
2722 int BestIdx = getBestVariantMatchForContext(VMIs, OMPCtx);
2726 bool HasNonConstUserCondition =
2727 llvm::any_of(TraitInfos, [&](OMPTraitInfo *TI) {
2733 if (HasNonConstUserCondition &&
2734 getLangOpts().OpenMPMetadirectiveRuntimeSelection) {
2738 unsigned NumClauses = TraitInfos.size();
2739 bool HasOtherwise = llvm::any_of(
2740 TraitInfos, [](
const OMPTraitInfo *TI) {
return TI->
Sets.empty(); });
2741 unsigned NumVariants = NumClauses + (HasOtherwise ? 0 : 1);
2747 SmallVector<Stmt *, 4> Variants;
2748 bool HasError =
false;
2749 for (
unsigned I : llvm::seq<unsigned>(NumVariants)) {
2750 bool HasDirective =
false;
2751 if (I < NumClauses) {
2755 if (CKind == OMPC_when) {
2761 HasDirective = Tok.isNot(tok::r_paren) &&
2762 Tok.isNot(tok::annot_pragma_openmp_end);
2765 std::optional<TentativeParsingAction> VariantTPA;
2766 if (I + 1 < NumVariants)
2767 VariantTPA.emplace(*
this,
true);
2771 Variant = ParseOpenMPDeclarativeOrExecutableDirective(
2775 while (Tok.isNot(tok::annot_pragma_openmp_end))
2777 ConsumeAnnotationToken();
2780 if (!Variant.isInvalid() && !Variant.isUsable()) {
2782 Variant = ParseStatement();
2786 if (
auto *D = dyn_cast_or_null<OMPExecutableDirective>(Variant.get());
2787 D && !D->hasAssociatedStmt()) {
2788 Diag(Loc, diag::err_omp_metadirective_standalone_variant);
2793 VariantTPA->Revert();
2797 if (Variant.isInvalid())
2800 Variants.push_back(Variant.get());
2804 return Actions.OpenMP().ActOnOpenMPMetaDirective(Loc, EndLoc, TraitInfos,
2813 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2815 if (Idx++ != BestIdx) {
2820 while (Tok.isNot(tok::r_paren) || paren != 0) {
2821 if (Tok.is(tok::l_paren))
2823 if (Tok.is(tok::r_paren))
2828 if (Tok.is(tok::r_paren))
2835 : getOpenMPClauseKind(PP.getSpelling(Tok));
2842 if (CKind == OMPC_when) {
2843 OMPTraitInfo &TI = Actions.getASTContext().getNewOMPTraitInfo();
2845 parseOMPContextSelectors(Loc, TI);
2853 if (Tok.is(tok::r_paren)) {
2854 SkipUntil(tok::annot_pragma_openmp_end);
2859 Directive = ParseOpenMPDeclarativeOrExecutableDirective(
2867 if (BestIdx == -1 && Idx > 0) {
2868 assert(Tok.is(tok::annot_pragma_openmp_end) &&
2869 "Expecting the end of the pragma here");
2870 ConsumeAnnotationToken();
2875 case OMPD_threadprivate: {
2877 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2878 ParsedStmtContext()) {
2879 Diag(Tok, diag::err_omp_immediate_directive)
2880 << getOpenMPDirectiveName(DKind, OMPVersion) << 0;
2883 DeclDirectiveListParserHelper Helper(
this, DKind);
2884 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2886 skipUntilPragmaOpenMPEnd(DKind);
2887 DeclGroupPtrTy Res = Actions.OpenMP().ActOnOpenMPThreadprivateDirective(
2888 Loc, Helper.getIdentifiers());
2889 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2891 SkipUntil(tok::annot_pragma_openmp_end);
2894 case OMPD_groupprivate: {
2895 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2896 ParsedStmtContext()) {
2897 Diag(Tok, diag::err_omp_immediate_directive)
2898 << getOpenMPDirectiveName(DKind, OMPVersion) << 0;
2901 DeclDirectiveListParserHelper Helper(
this, DKind);
2902 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2904 skipUntilPragmaOpenMPEnd(DKind);
2905 DeclGroupPtrTy Res = Actions.OpenMP().ActOnOpenMPGroupPrivateDirective(
2906 Loc, Helper.getIdentifiers());
2907 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2909 SkipUntil(tok::annot_pragma_openmp_end);
2912 case OMPD_allocate: {
2914 if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
2915 ParsedStmtContext()) {
2916 Diag(Tok, diag::err_omp_immediate_directive)
2917 << getOpenMPDirectiveName(DKind, OMPVersion) << 0;
2920 DeclDirectiveListParserHelper Helper(
this, DKind);
2921 if (!ParseOpenMPSimpleVarList(DKind, Helper,
2923 SmallVector<OMPClause *, 1> Clauses;
2924 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
2925 llvm::SmallBitVector SeenClauses(llvm::omp::Clause_enumSize + 1);
2926 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
2928 Tok.isAnnotation() ? OMPC_unknown
2929 : getOpenMPClauseKind(PP.getSpelling(Tok));
2930 Actions.OpenMP().StartOpenMPClause(CKind);
2931 OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind,
2932 !SeenClauses[
unsigned(CKind)]);
2933 SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
2935 SeenClauses[
unsigned(CKind)] =
true;
2936 if (Clause !=
nullptr)
2937 Clauses.push_back(Clause);
2938 if (Tok.is(tok::annot_pragma_openmp_end)) {
2939 Actions.OpenMP().EndOpenMPClause();
2943 if (Tok.is(tok::comma))
2945 Actions.OpenMP().EndOpenMPClause();
2947 skipUntilPragmaOpenMPEnd(DKind);
2949 DeclGroupPtrTy Res = Actions.OpenMP().ActOnOpenMPAllocateDirective(
2950 Loc, Helper.getIdentifiers(), Clauses);
2951 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2953 SkipUntil(tok::annot_pragma_openmp_end);
2956 case OMPD_declare_reduction:
2959 ParseOpenMPDeclareReductionDirective(
AS_none)) {
2960 skipUntilPragmaOpenMPEnd(OMPD_declare_reduction);
2962 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2964 SkipUntil(tok::annot_pragma_openmp_end);
2967 case OMPD_declare_mapper: {
2970 ParseOpenMPDeclareMapperDirective(
AS_none)) {
2972 ConsumeAnnotationToken();
2973 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
2975 SkipUntil(tok::annot_pragma_openmp_end);
2979 case OMPD_declare_target: {
2981 bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
2982 SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
2984 ParseOMPDeclareTargetClauses(DTCI);
2985 bool HasImplicitMappings =
2988 if (HasImplicitMappings) {
2989 Diag(Tok, diag::err_omp_unexpected_directive)
2990 << 1 << getOpenMPDirectiveName(DKind, OMPVersion);
2991 SkipUntil(tok::annot_pragma_openmp_end);
2998 Actions.OpenMP().ActOnFinishedOpenMPDeclareTargetContext(DTCI);
3001 case OMPD_begin_declare_variant: {
3006 ConsumeAnnotationToken();
3010 case OMPD_end_declare_variant: {
3012 if (Actions.OpenMP().isInOpenMPDeclareVariantScope())
3013 Actions.OpenMP().ActOnOpenMPEndDeclareVariant();
3015 Diag(Loc, diag::err_expected_begin_declare_variant);
3016 ConsumeAnnotationToken();
3019 case OMPD_declare_simd:
3020 case OMPD_begin_declare_target:
3021 case OMPD_end_declare_target:
3023 case OMPD_declare_variant:
3024 Diag(Tok, diag::err_omp_unexpected_directive)
3025 << 1 << getOpenMPDirectiveName(DKind, OMPVersion);
3026 SkipUntil(tok::annot_pragma_openmp_end);
3030 Directive = ParseOpenMPInformationalDirective(
3031 StmtCtx, DKind, Loc, ReadDirectiveWithinMetadirective);
3033 "Informational directive remains unprocessed");
3038 Diag(Tok, diag::err_omp_unknown_directive);
3039 SkipUntil(tok::annot_pragma_openmp_end);
3045bool Parser::ParseOpenMPSimpleVarList(
3049 bool AllowScopeSpecifier) {
3050 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
3053 if (
T.expectAndConsume(diag::err_expected_lparen_after,
3054 getOpenMPDirectiveName(Kind, OMPVersion).data()))
3056 bool IsCorrect =
true;
3057 bool NoIdentIsFound =
true;
3060 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
3064 Token PrevTok = Tok;
3065 NoIdentIsFound =
false;
3068 ParseOptionalCXXScopeSpecifier(SS,
nullptr,
3071 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3074 false,
false,
false,
3075 false,
false,
nullptr, Name)) {
3077 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3079 }
else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
3080 Tok.isNot(tok::annot_pragma_openmp_end)) {
3082 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3086 << SourceRange(PrevTok.
getLocation(), PrevTokLocation);
3088 Callback(SS, Actions.GetNameFromUnqualifiedId(Name));
3091 if (Tok.is(tok::comma)) {
3096 if (NoIdentIsFound) {
3097 Diag(Tok, diag::err_expected) << tok::identifier;
3102 IsCorrect = !
T.consumeClose() && IsCorrect;
3107OMPClause *Parser::ParseOpenMPSizesClause() {
3108 SourceLocation ClauseNameLoc, OpenLoc, CloseLoc;
3109 SmallVector<Expr *, 4> ValExprs;
3110 if (ParseOpenMPExprListClause(OMPC_sizes, ClauseNameLoc, OpenLoc, CloseLoc,
3114 return Actions.OpenMP().ActOnOpenMPSizesClause(ValExprs, ClauseNameLoc,
3118OMPClause *Parser::ParseOpenMPCountsClause() {
3119 SourceLocation ClauseNameLoc, OpenLoc, CloseLoc;
3120 SmallVector<Expr *, 4> ValExprs;
3121 std::optional<unsigned> FillIdx;
3122 unsigned FillCount = 0;
3123 SourceLocation FillLoc;
3125 assert(getOpenMPClauseName(OMPC_counts) == PP.getSpelling(Tok) &&
3126 "Expected parsing to start at clause name");
3130 if (
T.consumeOpen()) {
3131 Diag(Tok, diag::err_expected) << tok::l_paren;
3136 if (Tok.is(tok::identifier) &&
3137 Tok.getIdentifierInfo()->getName() ==
"omp_fill") {
3139 FillIdx = ValExprs.size();
3141 FillLoc = Tok.getLocation();
3143 ValExprs.push_back(
nullptr);
3150 ValExprs.push_back(Val.
get());
3154 if (
T.consumeClose())
3156 OpenLoc =
T.getOpenLocation();
3157 CloseLoc =
T.getCloseLocation();
3159 return Actions.OpenMP().ActOnOpenMPCountsClause(
3160 ValExprs, ClauseNameLoc, OpenLoc, CloseLoc, FillIdx, FillLoc, FillCount);
3163OMPClause *Parser::ParseOpenMPLoopRangeClause() {
3165 SourceLocation FirstLoc, CountLoc;
3168 if (
T.consumeOpen()) {
3169 Diag(Tok, diag::err_expected) << tok::l_paren;
3173 FirstLoc = Tok.getLocation();
3180 ExpectAndConsume(tok::comma);
3182 CountLoc = Tok.getLocation();
3191 return Actions.OpenMP().ActOnOpenMPLoopRangeClause(
3192 FirstVal.
get(), CountVal.
get(), ClauseNameLoc,
T.getOpenLocation(),
3193 FirstLoc, CountLoc,
T.getCloseLocation());
3196OMPClause *Parser::ParseOpenMPPermutationClause() {
3197 SourceLocation ClauseNameLoc, OpenLoc, CloseLoc;
3198 SmallVector<Expr *> ArgExprs;
3199 if (ParseOpenMPExprListClause(OMPC_permutation, ClauseNameLoc, OpenLoc,
3204 return Actions.OpenMP().ActOnOpenMPPermutationClause(ArgExprs, ClauseNameLoc,
3209 SourceLocation Loc = Tok.getLocation();
3214 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"uses_allocator"))
3216 SmallVector<SemaOpenMP::UsesAllocatorsData, 4>
Data;
3219 if (
getLangOpts().OpenMP >= 52 && Tok.is(tok::identifier) &&
3220 Tok.getIdentifierInfo()->getName() ==
"traits") {
3222 SemaOpenMP::UsesAllocatorsData &D =
Data.emplace_back();
3228 tok::annot_pragma_openmp_end);
3229 TraitParens.consumeOpen();
3232 TraitParens.consumeClose();
3236 {tok::comma, tok::semi, tok::r_paren, tok::annot_pragma_openmp_end},
3242 if (Tok.isNot(tok::colon)) {
3243 Diag(Tok, diag::err_expected) << tok::colon;
3245 {tok::comma, tok::semi, tok::r_paren, tok::annot_pragma_openmp_end},
3254 ? ParseCXXIdExpression()
3255 : tryParseCXXIdExpression(SS,
false);
3259 {tok::comma, tok::semi, tok::r_paren, tok::annot_pragma_openmp_end},
3266 D.
LParenLoc = TraitParens.getOpenLocation();
3267 D.
RParenLoc = TraitParens.getCloseLocation();
3270 if (Tok.is(tok::comma)) {
3272 Diag(Tok.getLocation(), diag::err_omp_allocator_comma_separator)
3275 }
else if (Tok.is(tok::semi)) {
3285 getLangOpts().CPlusPlus
3286 ? ParseCXXIdExpression()
3287 : tryParseCXXIdExpression(SS,
false);
3289 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3296 BalancedDelimiterTracker T(*this, tok::l_paren,
3297 tok::annot_pragma_openmp_end);
3299 ExprResult AllocatorTraits =
3300 getLangOpts().CPlusPlus ? ParseCXXIdExpression() : ParseExpression();
3302 if (AllocatorTraits.isInvalid()) {
3303 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
3312 if (getLangOpts().OpenMP >= 52) {
3313 Diag(Loc, diag::err_omp_deprecate_old_syntax)
3314 <<
"allocator(expr)"
3315 <<
"uses_allocators"
3316 <<
"traits(expr): alloc";
3320 Diag(
Tok, diag::err_omp_expected_punc) <<
"uses_allocators" << 0;
3322 if (
Tok.
is(tok::comma))
3324 }
while (
Tok.
isNot(tok::r_paren) &&
Tok.
isNot(tok::annot_pragma_openmp_end));
3327 Loc,
T.getOpenLocation(),
T.getCloseLocation(),
Data);
3332 OMPClauseKind = CKind;
3333 OMPClause *Clause =
nullptr;
3334 bool ErrorFound =
false;
3335 bool WrongDirective =
false;
3336 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
3339 if (!isAllowedClauseForDirective(D,
C, OMPVersion)) {
3340 Diag(Tok, diag::err_omp_unexpected_clause)
3341 << getOpenMPClauseName(
C) << getOpenMPDirectiveName(D, OMPVersion);
3343 WrongDirective =
true;
3347 if (CKind != OMPC_unknown) {
3349 assert(DKind != OMPD_ordered_blockassoc &&
3350 "Wrong kind for ordered directive");
3351 if (DKind == OMPD_ordered_standalone) {
3354 if (!isAllowedClauseForDirective(DKind, CKind, OMPVersion))
3355 CheckClauseValid(OMPD_ordered_blockassoc, CKind);
3357 CheckClauseValid(DKind, CKind);
3368 case OMPC_grainsize:
3369 case OMPC_num_tasks:
3371 case OMPC_allocator:
3374 case OMPC_novariants:
3375 case OMPC_nocontext:
3381 case OMPC_ompx_dyn_cgroup_mem:
3382 case OMPC_dyn_groupprivate:
3383 case OMPC_transparent:
3412 Diag(Tok, diag::err_omp_more_one_clause)
3413 << getOpenMPDirectiveName(DKind, OMPVersion)
3414 << getOpenMPClauseName(CKind) << 0;
3418 if (CKind == OMPC_transparent && PP.LookAhead(0).isNot(tok::l_paren)) {
3420 SourceLocation LLoc = Tok.getLocation();
3421 if (!WrongDirective)
3422 Clause = Actions.OpenMP().ActOnOpenMPTransparentClause(
nullptr, LLoc,
3426 if ((CKind == OMPC_ordered || CKind == OMPC_partial) &&
3427 PP.LookAhead(0).isNot(tok::l_paren))
3428 Clause = ParseOpenMPClause(CKind, WrongDirective);
3429 else if (CKind == OMPC_grainsize || CKind == OMPC_num_tasks ||
3430 CKind == OMPC_dyn_groupprivate)
3431 Clause = ParseOpenMPSingleExprWithArgClause(DKind, CKind, WrongDirective);
3433 Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
3435 case OMPC_threadset:
3437 case OMPC_proc_bind:
3438 case OMPC_atomic_default_mem_order:
3456 Diag(Tok, diag::err_omp_more_one_clause)
3457 << getOpenMPDirectiveName(DKind, OMPVersion)
3458 << getOpenMPClauseName(CKind) << 0;
3462 Clause = ParseOpenMPSimpleClause(CKind, WrongDirective);
3466 case OMPC_dist_schedule:
3467 case OMPC_defaultmap:
3478 if ((
getLangOpts().OpenMP < 50 || CKind != OMPC_defaultmap) &&
3479 (CKind != OMPC_order ||
getLangOpts().OpenMP >= 51) && !FirstClause) {
3480 Diag(Tok, diag::err_omp_more_one_clause)
3481 << getOpenMPDirectiveName(DKind, OMPVersion)
3482 << getOpenMPClauseName(CKind) << 0;
3487 Clause = ParseOpenMPSingleExprWithArgClause(DKind, CKind, WrongDirective);
3490 Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
3494 case OMPC_mergeable:
3508 case OMPC_unified_address:
3509 case OMPC_unified_shared_memory:
3510 case OMPC_reverse_offload:
3511 case OMPC_dynamic_allocators:
3520 Diag(Tok, diag::err_omp_more_one_clause)
3521 << getOpenMPDirectiveName(DKind, OMPVersion)
3522 << getOpenMPClauseName(CKind) << 0;
3526 if (CKind == OMPC_nowait && PP.LookAhead(0).is(tok::l_paren) &&
3528 Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective);
3530 Clause = ParseOpenMPClause(CKind, WrongDirective);
3532 case OMPC_self_maps:
3535 Diag(Tok, diag::err_omp_expected_clause)
3536 << getOpenMPDirectiveName(OMPD_requires, OMPVersion);
3540 Diag(Tok, diag::err_omp_more_one_clause)
3541 << getOpenMPDirectiveName(DKind, OMPVersion)
3542 << getOpenMPClauseName(CKind) << 0;
3545 Clause = ParseOpenMPClause(CKind, WrongDirective);
3549 Diag(Tok, diag::err_omp_more_one_clause)
3550 << getOpenMPDirectiveName(DKind, OMPVersion)
3551 << getOpenMPClauseName(CKind) << 0;
3554 Clause = ParseOpenMPClause(CKind, WrongDirective);
3556 case OMPC_update_depend_objects:
3558 Diag(Tok, diag::err_omp_more_one_clause)
3559 << getOpenMPDirectiveName(DKind, OMPVersion)
3560 << getOpenMPClauseName(CKind) << 0;
3564 Clause = ParseOpenMPSimpleClause(CKind, WrongDirective);
3566 case OMPC_num_teams:
3567 case OMPC_thread_limit:
3568 case OMPC_num_threads:
3570 Diag(Tok, diag::err_omp_more_one_clause)
3571 << getOpenMPDirectiveName(DKind, OMPVersion)
3572 << getOpenMPClauseName(CKind) << 0;
3577 case OMPC_firstprivate:
3578 case OMPC_lastprivate:
3580 case OMPC_reduction:
3581 case OMPC_task_reduction:
3582 case OMPC_in_reduction:
3586 case OMPC_copyprivate:
3592 case OMPC_use_device_ptr:
3593 case OMPC_use_device_addr:
3594 case OMPC_is_device_ptr:
3595 case OMPC_has_device_addr:
3597 case OMPC_nontemporal:
3598 case OMPC_inclusive:
3599 case OMPC_exclusive:
3603 if (
getLangOpts().OpenMP >= 52 && DKind == OMPD_ordered_standalone &&
3604 CKind == OMPC_depend)
3605 Diag(Tok, diag::warn_omp_depend_in_ordered_deprecated);
3606 Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective);
3610 Diag(Tok, diag::err_omp_more_one_clause)
3611 << getOpenMPDirectiveName(DKind, OMPVersion)
3612 << getOpenMPClauseName(CKind) << 0;
3616 Clause = ParseOpenMPSizesClause();
3618 case OMPC_permutation:
3620 Diag(Tok, diag::err_omp_more_one_clause)
3621 << getOpenMPDirectiveName(DKind, OMPVersion)
3622 << getOpenMPClauseName(CKind) << 0;
3625 Clause = ParseOpenMPPermutationClause();
3629 Diag(Tok, diag::err_omp_more_one_clause)
3630 << getOpenMPDirectiveName(DKind, OMPVersion)
3631 << getOpenMPClauseName(CKind) << 0;
3634 Clause = ParseOpenMPCountsClause();
3636 case OMPC_uses_allocators:
3637 Clause = ParseOpenMPUsesAllocatorClause(DKind);
3640 if (DKind != OMPD_interop) {
3642 Diag(Tok, diag::err_omp_more_one_clause)
3643 << getOpenMPDirectiveName(DKind, OMPVersion)
3644 << getOpenMPClauseName(CKind) << 0;
3647 Clause = ParseOpenMPClause(CKind, WrongDirective);
3653 Clause = ParseOpenMPInteropClause(CKind, WrongDirective);
3655 case OMPC_device_type:
3657 skipUntilPragmaOpenMPEnd(DKind);
3659 case OMPC_threadprivate:
3660 case OMPC_groupprivate:
3663 if (!WrongDirective)
3664 Diag(Tok, diag::err_omp_unexpected_clause)
3665 << getOpenMPClauseName(CKind)
3666 << getOpenMPDirectiveName(DKind, OMPVersion);
3670 case OMPC_contains: {
3672 SourceLocation LLoc = Tok.getLocation();
3673 SourceLocation RLoc;
3674 llvm::SmallVector<OpenMPDirectiveKind, 4> DKVec;
3679 if (DK == OMPD_unknown) {
3680 skipUntilPragmaOpenMPEnd(OMPD_assume);
3681 Diag(Tok, diag::err_omp_unexpected_clause)
3682 << getOpenMPClauseName(CKind)
3683 << getOpenMPDirectiveName(DKind, OMPVersion);
3687 DKVec.push_back(DK);
3690 Diag(Tok, diag::err_omp_unexpected_clause)
3691 << getOpenMPClauseName(CKind)
3692 << getOpenMPDirectiveName(DKind, OMPVersion);
3695 RLoc = Tok.getLocation();
3697 if (!WrongDirective)
3698 Clause = Actions.OpenMP().ActOnOpenMPDirectivePresenceClause(
3699 CKind, DKVec, Loc, LLoc, RLoc);
3702 case OMPC_no_openmp:
3703 case OMPC_no_openmp_routines:
3704 case OMPC_no_openmp_constructs:
3705 case OMPC_no_parallelism: {
3707 Diag(Tok, diag::err_omp_more_one_clause)
3708 << getOpenMPDirectiveName(DKind, OMPVersion)
3709 << getOpenMPClauseName(CKind) << 0;
3713 if (!WrongDirective)
3714 Clause = Actions.OpenMP().ActOnOpenMPNullaryAssumptionClause(
3715 CKind, Loc, Tok.getLocation());
3718 case OMPC_ompx_attribute:
3719 Clause = ParseOpenMPOMPXAttributesClause(WrongDirective);
3721 case OMPC_ompx_bare:
3722 if (DKind == llvm::omp::Directive::OMPD_target) {
3727 Diag(Tok, diag::err_omp_unexpected_clause)
3728 << getOpenMPClauseName(CKind)
3729 << getOpenMPDirectiveName(DKind, OMPVersion);
3731 WrongDirective =
true;
3734 Diag(Tok, diag::note_ompx_bare_clause)
3735 << getOpenMPClauseName(CKind) <<
"target teams";
3736 if (!ErrorFound && !
getLangOpts().OpenMPExtensions) {
3737 Diag(Tok, diag::err_omp_unexpected_clause_extension_only)
3738 << getOpenMPClauseName(CKind)
3739 << getOpenMPDirectiveName(DKind, OMPVersion);
3742 Clause = ParseOpenMPClause(CKind, WrongDirective);
3744 case OMPC_looprange:
3745 Clause = ParseOpenMPLoopRangeClause();
3750 return ErrorFound ?
nullptr : Clause;
3758 bool IsAddressOfOperand) {
3760 if (
T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data()))
3768 Val = Actions.ActOnFinishFullExpr(Val.
get(), ELoc,
false);
3771 RLoc = Tok.getLocation();
3772 if (!
T.consumeClose())
3773 RLoc =
T.getCloseLocation();
3795bool Parser::ParseOpenMPIndirectClause(
3800 if (
Tok.isNot(tok::l_paren)) {
3819 if (
Ret.isInvalid())
3822 Ret = Actions.VerifyIntegerConstantExpression(Val.
get(), &
Result,
3824 if (
Ret.isInvalid())
3832ExprResult Parser::ParseOMPInteropFrSelector() {
3835 tok::annot_pragma_openmp_end);
3836 if (FT.expectAndConsume(diag::err_expected_lparen_after,
"fr")) {
3838 {tok::comma, tok::r_brace, tok::r_paren, tok::annot_pragma_openmp_end},
3842 SourceLocation Loc = Tok.getLocation();
3845 Arg = Actions.ActOnFinishFullExpr(Arg.
get(), Loc,
false);
3853 tok::annot_pragma_openmp_end);
3854 if (AT.expectAndConsume(diag::err_expected_lparen_after,
"attr")) {
3856 {tok::comma, tok::r_brace, tok::r_paren, tok::annot_pragma_openmp_end},
3860 bool HasError =
false;
3863 if (Tok.is(tok::r_paren)) {
3864 Diag(Tok, diag::err_omp_interop_attr_not_string);
3867 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::r_brace) &&
3868 Tok.isNot(tok::annot_pragma_openmp_end)) {
3869 if (Tok.is(tok::string_literal)) {
3872 Attrs.push_back(S.
get());
3877 Diag(Tok, diag::err_omp_interop_attr_not_string);
3880 if (Tok.is(tok::comma))
3890 bool HasError =
false;
3891 bool IsTarget =
false;
3892 bool IsTargetSync =
false;
3894 while (Tok.is(tok::identifier)) {
3896 bool PreferTypeAllowed = (
Kind == OMPC_init ||
Kind == OMPC_append_args) &&
3897 InteropInfo.
Prefs.empty() && !IsTarget &&
3899 if (Tok.getIdentifierInfo()->isStr(
"target")) {
3904 Diag(Tok, diag::warn_omp_more_one_interop_type) <<
"target";
3907 }
else if (Tok.getIdentifierInfo()->isStr(
"targetsync")) {
3909 Diag(Tok, diag::warn_omp_more_one_interop_type) <<
"targetsync";
3910 IsTargetSync =
true;
3912 }
else if (Tok.getIdentifierInfo()->isStr(
"prefer_type") &&
3913 PreferTypeAllowed) {
3914 if (Kind == OMPC_append_args &&
getLangOpts().OpenMP < 60) {
3915 Diag(Tok, diag::err_omp_append_args_prefer_type_60);
3920 tok::annot_pragma_openmp_end);
3921 if (PT.expectAndConsume(diag::err_expected_lparen_after,
"prefer_type"))
3925 if (Tok.is(tok::r_paren)) {
3926 Diag(Tok, diag::err_omp_expected_pref_spec);
3930 while (Tok.isNot(tok::r_paren) &&
3931 Tok.isNot(tok::annot_pragma_openmp_end)) {
3933 if (Tok.is(tok::l_brace)) {
3937 Diag(Tok, diag::err_omp_prefer_type_brace_60);
3941 tok::annot_pragma_openmp_end);
3943 Expr *FrExpr =
nullptr;
3944 SmallVector<Expr *, 2> AttrExprs;
3945 bool SeenFr =
false;
3949 if (Tok.is(tok::r_brace)) {
3950 Diag(Tok, diag::err_omp_expected_fr_or_attr_selector);
3954 while (Tok.isNot(tok::r_brace) &&
3955 Tok.isNot(tok::annot_pragma_openmp_end)) {
3956 if (Tok.is(tok::identifier) &&
3957 Tok.getIdentifierInfo()->isStr(
"fr")) {
3959 Diag(Tok, diag::err_omp_interop_multiple_fr);
3963 {tok::comma, tok::r_brace, tok::annot_pragma_openmp_end},
3973 }
else if (Tok.is(tok::identifier) &&
3974 Tok.getIdentifierInfo()->isStr(
"attr")) {
3975 if (ParseOMPInteropAttrSelector(AttrExprs))
3980 Diag(Tok, diag::err_omp_expected_fr_or_attr_selector);
3983 if (Tok.is(tok::comma))
3986 if (BT.consumeClose())
3989 if (FrExpr || !AttrExprs.empty())
3990 InteropInfo.
Prefs.emplace_back(FrExpr, AttrExprs);
3995 SourceLocation Loc = Tok.getLocation();
3999 PTExpr = Actions.ActOnFinishFullExpr(PTExpr.
get(), Loc,
4002 InteropInfo.
Prefs.emplace_back(PTExpr.
get(),
4003 llvm::SmallVector<Expr *, 2>{});
4006 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
4011 if (Tok.is(tok::comma))
4017 Diag(Tok, diag::err_omp_expected_interop_type);
4020 if (!Tok.is(tok::comma))
4025 if (!HasError && !IsTarget && !IsTargetSync) {
4026 Diag(Tok, diag::err_omp_expected_interop_type);
4030 if (Kind == OMPC_init) {
4031 if (Tok.isNot(tok::colon) && (IsTarget || IsTargetSync))
4032 Diag(Tok, diag::warn_pragma_expected_colon) <<
"interop types";
4033 if (Tok.is(tok::colon))
4050 if (
T.expectAndConsume(diag::err_expected_lparen_after,
4051 getOpenMPClauseName(Kind).data()))
4054 bool InteropError =
false;
4055 OMPInteropInfo InteropInfo;
4056 if (Kind == OMPC_init)
4057 InteropError = ParseOMPInteropInfo(InteropInfo, OMPC_init);
4060 SourceLocation VarLoc = Tok.getLocation();
4063 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
4068 SourceLocation RLoc = Tok.getLocation();
4069 if (!
T.consumeClose())
4070 RLoc =
T.getCloseLocation();
4072 if (ParseOnly || !InteropVarExpr.
isUsable() || InteropError)
4075 if (Kind == OMPC_init)
4076 return Actions.OpenMP().ActOnOpenMPInitClause(
4077 InteropVarExpr.
get(), InteropInfo, Loc,
T.getOpenLocation(), VarLoc,
4079 if (Kind == OMPC_use)
4080 return Actions.OpenMP().ActOnOpenMPUseClause(
4081 InteropVarExpr.
get(), Loc,
T.getOpenLocation(), VarLoc, RLoc);
4083 if (Kind == OMPC_destroy)
4084 return Actions.OpenMP().ActOnOpenMPDestroyClause(
4085 InteropVarExpr.
get(), Loc,
T.getOpenLocation(), VarLoc, RLoc);
4087 llvm_unreachable(
"Unexpected interop variable clause.");
4090OMPClause *Parser::ParseOpenMPOMPXAttributesClause(
bool ParseOnly) {
4094 if (
T.expectAndConsume(diag::err_expected_lparen_after,
4095 getOpenMPClauseName(OMPC_ompx_attribute).data()))
4098 ParsedAttributes ParsedAttrs(AttrFactory);
4099 ParseAttributes(PAKM_GNU | PAKM_CXX11, ParsedAttrs);
4102 if (
T.consumeClose())
4108 SmallVector<Attr *> Attrs;
4109 for (
const ParsedAttr &PA : ParsedAttrs) {
4110 switch (PA.getKind()) {
4111 case ParsedAttr::AT_AMDGPUFlatWorkGroupSize:
4112 if (!PA.checkExactlyNumArgs(Actions, 2))
4114 if (
auto *A = Actions.AMDGPU().CreateAMDGPUFlatWorkGroupSizeAttr(
4115 PA, PA.getArgAsExpr(0), PA.getArgAsExpr(1)))
4118 case ParsedAttr::AT_AMDGPUWavesPerEU:
4119 if (!PA.checkAtLeastNumArgs(Actions, 1) ||
4120 !PA.checkAtMostNumArgs(Actions, 2))
4122 if (
auto *A = Actions.AMDGPU().CreateAMDGPUWavesPerEUAttr(
4123 PA, PA.getArgAsExpr(0),
4124 PA.getNumArgs() > 1 ? PA.getArgAsExpr(1) :
nullptr))
4127 case ParsedAttr::AT_CUDALaunchBounds:
4128 if (!PA.checkAtLeastNumArgs(Actions, 1) ||
4129 !PA.checkAtMostNumArgs(Actions, 3))
4131 if (
auto *A = Actions.CreateLaunchBoundsAttr(
4132 PA, PA.getArgAsExpr(0),
4133 PA.getNumArgs() > 1 ? PA.getArgAsExpr(1) :
nullptr,
4134 PA.getNumArgs() > 2 ? PA.getArgAsExpr(2) :
nullptr,
4139 Diag(Loc, diag::warn_omp_invalid_attribute_for_ompx_attributes) << PA;
4144 return Actions.OpenMP().ActOnOpenMPXAttributeClause(
4145 Attrs, Loc,
T.getOpenLocation(),
T.getCloseLocation());
4151 if (!Val || ParseOnly)
4153 if (
getLangOpts().OpenMP < 51 && Kind == OMPC_default &&
4154 (
static_cast<DefaultKind
>(Val->Type) == OMP_DEFAULT_private ||
4155 static_cast<DefaultKind
>(Val->Type) ==
4156 OMP_DEFAULT_firstprivate)) {
4157 Diag(Val->LOpen, diag::err_omp_invalid_dsa)
4158 << getOpenMPClauseName(
static_cast<DefaultKind
>(Val->Type) ==
4161 : OMPC_firstprivate)
4162 << getOpenMPClauseName(OMPC_default) <<
"5.1";
4165 return Actions.OpenMP().ActOnOpenMPSimpleClause(
4166 Kind, Val->Type, Val->TypeLoc, Val->LOpen, Val->Loc, Val->RLoc);
4170 SourceLocation Loc = Tok.getLocation();
4175 return Actions.OpenMP().ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
4182 SourceLocation DelimLoc;
4185 if (
T.expectAndConsume(diag::err_expected_lparen_after,
4186 getOpenMPClauseName(Kind).data()))
4190 SmallVector<unsigned, 4> Arg;
4191 SmallVector<SourceLocation, 4> KLoc;
4192 if (Kind == OMPC_schedule) {
4193 enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements };
4194 Arg.resize(NumberOfElements);
4195 KLoc.resize(NumberOfElements);
4200 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4203 Arg[Modifier1] = KindModifier;
4204 KLoc[Modifier1] = Tok.getLocation();
4205 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4206 Tok.isNot(tok::annot_pragma_openmp_end))
4208 if (Tok.is(tok::comma)) {
4212 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4216 KLoc[Modifier2] = Tok.getLocation();
4217 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4218 Tok.isNot(tok::annot_pragma_openmp_end))
4222 if (Tok.is(tok::colon))
4225 Diag(Tok, diag::warn_pragma_expected_colon) <<
"schedule modifier";
4227 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4229 Arg[ScheduleKind] = KindModifier;
4230 KLoc[ScheduleKind] = Tok.getLocation();
4231 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4232 Tok.isNot(tok::annot_pragma_openmp_end))
4234 if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static ||
4235 Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic ||
4236 Arg[ScheduleKind] == OMPC_SCHEDULE_guided) &&
4239 }
else if (Kind == OMPC_dist_schedule) {
4241 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts()));
4242 KLoc.push_back(Tok.getLocation());
4243 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4244 Tok.isNot(tok::annot_pragma_openmp_end))
4246 if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma))
4248 }
else if (Kind == OMPC_default) {
4251 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4253 Arg.push_back(Modifier);
4254 KLoc.push_back(Tok.getLocation());
4255 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4256 Tok.isNot(tok::annot_pragma_openmp_end))
4259 if (Tok.is(tok::colon) &&
getLangOpts().OpenMP >= 60) {
4264 Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4265 Arg.push_back(VariableCategory);
4266 KLoc.push_back(Tok.getLocation());
4267 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4268 Tok.isNot(tok::annot_pragma_openmp_end))
4271 Arg.push_back(OMPC_DEFAULT_VC_all);
4272 KLoc.push_back(SourceLocation());
4274 }
else if (Kind == OMPC_defaultmap) {
4277 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4283 Arg.push_back(Modifier);
4284 KLoc.push_back(Tok.getLocation());
4285 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4286 Tok.isNot(tok::annot_pragma_openmp_end))
4289 if (Tok.is(tok::colon) ||
getLangOpts().OpenMP < 50) {
4290 if (Tok.is(tok::colon))
4293 Diag(Tok, diag::warn_pragma_expected_colon) <<
"defaultmap modifier";
4296 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts()));
4297 KLoc.push_back(Tok.getLocation());
4298 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4299 Tok.isNot(tok::annot_pragma_openmp_end))
4303 KLoc.push_back(SourceLocation());
4305 }
else if (Kind == OMPC_order) {
4306 enum { Modifier, OrderKind, NumberOfElements };
4307 Arg.resize(NumberOfElements);
4308 KLoc.resize(NumberOfElements);
4312 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4315 Arg[Modifier] = KindModifier;
4316 KLoc[Modifier] = Tok.getLocation();
4317 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4318 Tok.isNot(tok::annot_pragma_openmp_end))
4321 if (Tok.is(tok::colon))
4324 Diag(Tok, diag::warn_pragma_expected_colon) <<
"order modifier";
4326 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4328 Arg[OrderKind] = KindModifier;
4329 KLoc[OrderKind] = Tok.getLocation();
4330 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4331 Tok.isNot(tok::annot_pragma_openmp_end))
4333 }
else if (Kind == OMPC_device) {
4339 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts()));
4340 KLoc.push_back(Tok.getLocation());
4346 KLoc.emplace_back();
4348 }
else if (Kind == OMPC_grainsize) {
4352 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
4356 Arg.push_back(Modifier);
4357 KLoc.push_back(Tok.getLocation());
4363 if (Modifier == OMPC_GRAINSIZE_strict) {
4364 Diag(Tok, diag::err_modifier_expected_colon) <<
"strict";
4369 KLoc.emplace_back();
4373 KLoc.emplace_back();
4375 }
else if (Kind == OMPC_dyn_groupprivate) {
4376 enum { SimpleModifier, ComplexModifier, NumberOfModifiers };
4377 Arg.resize(NumberOfModifiers);
4378 KLoc.resize(NumberOfModifiers);
4382 auto ConsumeModifier = [&]() {
4383 unsigned Type = NumberOfModifiers;
4386 if (!Tok.isAnnotation() && PP.getSpelling(Tok) ==
"fallback" &&
4390 ParenT.consumeOpen();
4393 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4396 Diag(Tok.getLocation(), diag::err_expected)
4397 <<
"'abort', 'null' or 'default_mem' in fallback modifier";
4399 return std::make_tuple(
Type, Modifier, Loc);
4401 Type = ComplexModifier;
4402 Loc = Tok.getLocation();
4403 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4404 Tok.isNot(tok::annot_pragma_openmp_end))
4406 ParenT.consumeClose();
4409 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
getLangOpts());
4411 Type = SimpleModifier;
4412 Loc = Tok.getLocation();
4413 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
4414 Tok.isNot(tok::annot_pragma_openmp_end))
4418 return std::make_tuple(
Type, Modifier, Loc);
4421 auto SaveModifier = [&](
unsigned Type,
unsigned Modifier,
4422 SourceLocation Loc) {
4423 assert(
Type < NumberOfModifiers &&
"Unexpected modifier type");
4424 if (!KLoc[
Type].isValid()) {
4425 Arg[
Type] = Modifier;
4428 Diag(Loc, diag::err_omp_incompatible_dyn_groupprivate_modifier)
4435 auto [Type1, Mod1, Loc1] = ConsumeModifier();
4436 if (Type1 < NumberOfModifiers) {
4437 SaveModifier(Type1, Mod1, Loc1);
4438 if (Tok.is(tok::comma)) {
4441 auto [Type2, Mod2, Loc2] = ConsumeModifier();
4442 if (Type2 < NumberOfModifiers)
4443 SaveModifier(Type2, Mod2, Loc2);
4446 if (Tok.is(tok::colon))
4449 Diag(Tok, diag::warn_pragma_expected_colon)
4450 <<
"dyn_groupprivate modifier";
4452 }
else if (Kind == OMPC_num_tasks) {
4456 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
4460 Arg.push_back(Modifier);
4461 KLoc.push_back(Tok.getLocation());
4467 if (Modifier == OMPC_NUMTASKS_strict) {
4468 Diag(Tok, diag::err_modifier_expected_colon) <<
"strict";
4473 KLoc.emplace_back();
4477 KLoc.emplace_back();
4480 assert(Kind == OMPC_if);
4481 KLoc.push_back(Tok.getLocation());
4482 TentativeParsingAction TPA(*
this);
4484 Arg.push_back(
static_cast<unsigned>(DK));
4485 if (DK != OMPD_unknown) {
4487 if (Tok.is(tok::colon) &&
getLangOpts().OpenMP > 40) {
4492 Arg.back() =
unsigned(OMPD_unknown);
4499 bool NeedAnExpression = (
Kind == OMPC_schedule && DelimLoc.
isValid()) ||
4500 (
Kind == OMPC_dist_schedule && DelimLoc.
isValid()) ||
4501 Kind == OMPC_if ||
Kind == OMPC_device ||
4502 Kind == OMPC_grainsize ||
Kind == OMPC_num_tasks ||
4503 Kind == OMPC_dyn_groupprivate;
4504 if (NeedAnExpression) {
4505 SourceLocation ELoc = Tok.getLocation();
4511 Actions.ActOnFinishFullExpr(Val.
get(), ELoc,
false);
4515 SourceLocation RLoc = Tok.getLocation();
4516 if (!
T.consumeClose())
4517 RLoc =
T.getCloseLocation();
4519 if (NeedAnExpression && Val.
isInvalid())
4522 if (Kind == OMPC_default &&
getLangOpts().OpenMP < 51 && Arg[0] &&
4523 (
static_cast<DefaultKind
>(Arg[0]) == OMP_DEFAULT_private ||
4524 static_cast<DefaultKind
>(Arg[0]) == OMP_DEFAULT_firstprivate)) {
4525 Diag(KLoc[0], diag::err_omp_invalid_dsa)
4526 << getOpenMPClauseName(
static_cast<DefaultKind
>(Arg[0]) ==
4529 : OMPC_firstprivate)
4530 << getOpenMPClauseName(OMPC_default) <<
"5.1";
4536 return Actions.OpenMP().ActOnOpenMPSingleExprWithArgClause(
4537 Kind, Arg, Val.
get(), Loc,
T.getOpenLocation(), KLoc, DelimLoc, RLoc);
4542 if (ReductionIdScopeSpec.
isEmpty()) {
4580 ReductionIdScopeSpec,
nullptr,
4584 false,
nullptr, ReductionId);
4591 if (!
Tok.is(tok::identifier))
4598 return TypeModifier;
4604 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"mapper")) {
4605 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
4611 ParseOptionalCXXScopeSpecifier(
Data.ReductionOrMapperIdScopeSpec,
4615 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) {
4616 Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier);
4617 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
4621 auto &DeclNames = Actions.getASTContext().DeclarationNames;
4623 DeclNames.getIdentifier(Tok.getIdentifierInfo()), Tok.getLocation());
4626 return T.consumeClose();
4632 bool HasMapType =
false;
4634 StringRef PreMapName =
"";
4638 if (TypeModifier == OMPC_MAP_MODIFIER_always ||
4639 TypeModifier == OMPC_MAP_MODIFIER_close ||
4640 TypeModifier == OMPC_MAP_MODIFIER_present ||
4641 TypeModifier == OMPC_MAP_MODIFIER_ompx_hold) {
4642 Data.MapTypeModifiers.push_back(TypeModifier);
4643 Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
4644 if (PP.LookAhead(0).isNot(tok::comma) &&
4645 PP.LookAhead(0).isNot(tok::colon) &&
getLangOpts().OpenMP >= 52)
4646 Diag(Tok.getLocation(), diag::err_omp_missing_comma)
4647 <<
"map type modifier";
4649 }
else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) {
4650 Data.MapTypeModifiers.push_back(TypeModifier);
4651 Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
4655 if (Tok.isNot(tok::comma) && Tok.isNot(tok::colon) &&
4657 Diag(
Data.MapTypeModifiersLoc.back(), diag::err_omp_missing_comma)
4658 <<
"map type modifier";
4663 Data.ExtraModifier = MapKind;
4665 PreMapLoc = Tok.getLocation();
4666 PreMapName = Tok.getIdentifierInfo()->getName();
4668 Diag(Tok, diag::err_omp_more_one_map_type);
4669 Diag(PreMapLoc, diag::note_previous_map_type_specified_here)
4673 }
else if (TypeModifier == OMPC_MAP_MODIFIER_self) {
4674 Data.MapTypeModifiers.push_back(TypeModifier);
4675 Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
4676 if (PP.LookAhead(0).isNot(tok::comma) &&
4677 PP.LookAhead(0).isNot(tok::colon))
4678 Diag(Tok.getLocation(), diag::err_omp_missing_comma)
4679 <<
"map type modifier";
4681 Diag(Tok, diag::err_omp_unknown_map_type_modifier)
4691 if (Tok.is(tok::comma)) {
4692 Diag(Tok, diag::err_omp_map_type_modifier_missing);
4697 if (PP.LookAhead(0).is(tok::colon)) {
4705 Diag(Tok, diag::err_omp_unknown_map_type_modifier)
4716 if (!Tok.is(tok::colon)) {
4717 Diag(Tok, diag::err_omp_unknown_map_type);
4731 if (!
Tok.isOneOf(tok::identifier, tok::kw_delete))
4736 if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_from ||
4737 MapType == OMPC_MAP_tofrom || MapType == OMPC_MAP_alloc ||
4738 MapType == OMPC_MAP_delete || MapType == OMPC_MAP_release)
4748 if (
Tok.is(tok::colon)) {
4749 P.
Diag(
Tok, diag::err_omp_map_type_missing);
4754 P.
Diag(
Tok, diag::err_omp_unknown_map_type);
4758ExprResult Parser::ParseOpenMPIteratorsExpr() {
4759 assert(Tok.is(tok::identifier) && PP.getSpelling(Tok) ==
"iterator" &&
4760 "Expected 'iterator' token.");
4764 if (
T.expectAndConsume(diag::err_expected_lparen_after,
"iterator"))
4767 SourceLocation LLoc =
T.getOpenLocation();
4768 SmallVector<SemaOpenMP::OMPIteratorData, 4>
Data;
4769 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
4772 if (Tok.isNot(tok::identifier) ||
NextToken().
isNot(tok::equal)) {
4779 IteratorType = TR.
get();
4783 IdentifierInfo *II =
nullptr;
4784 SourceLocation IdLoc;
4785 if (Tok.is(tok::identifier)) {
4786 II = Tok.getIdentifierInfo();
4789 Diag(Tok, diag::err_expected_unqualified_id) << 0;
4793 SourceLocation AssignLoc;
4794 if (Tok.is(tok::equal))
4797 Diag(Tok, diag::err_omp_expected_equal_in_iterator);
4802 SourceLocation Loc = Tok.getLocation();
4805 Begin = Actions.ActOnFinishFullExpr(Begin.
get(), Loc,
4808 SourceLocation ColonLoc;
4809 if (Tok.is(tok::colon))
4813 Loc = Tok.getLocation();
4816 End = Actions.ActOnFinishFullExpr(End.
get(), Loc,
4819 SourceLocation SecColonLoc;
4822 if (Tok.is(tok::colon)) {
4826 Loc = Tok.getLocation();
4829 Step = Actions.ActOnFinishFullExpr(Step.
get(), Loc,
4834 if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren))
4835 Diag(Tok, diag::err_omp_expected_punc_after_iterator);
4836 if (Tok.is(tok::comma))
4839 SemaOpenMP::OMPIteratorData &D =
Data.emplace_back();
4842 D.
Type = IteratorType;
4852 SourceLocation RLoc = Tok.getLocation();
4853 if (!
T.consumeClose())
4854 RLoc =
T.getCloseLocation();
4856 return Actions.OpenMP().ActOnOMPIteratorExpr(
getCurScope(), IteratorKwLoc,
4865 if (Kind != OMPC_depend || LangOpts.OpenMP < 51)
4868 if (Tok.is(tok::identifier) &&
4869 Tok.getIdentifierInfo()->isStr(
"omp_all_memory")) {
4871 if (
Data.ExtraModifier == OMPC_DEPEND_outallmemory ||
4872 Data.ExtraModifier == OMPC_DEPEND_inoutallmemory)
4873 Diag(Tok, diag::warn_omp_more_one_omp_all_memory);
4874 else if (
Data.ExtraModifier != OMPC_DEPEND_out &&
4875 Data.ExtraModifier != OMPC_DEPEND_inout)
4876 Diag(Tok, diag::err_omp_requires_out_inout_depend_type);
4878 Data.ExtraModifier =
Data.ExtraModifier == OMPC_DEPEND_out
4879 ? OMPC_DEPEND_outallmemory
4880 : OMPC_DEPEND_inoutallmemory;
4890 if (Tok.isNot(tok::identifier) ||
4891 !Tok.getIdentifierInfo()->isStr(
"omp_num_args")) {
4906 if (Tok.isOneOf(tok::plus, tok::minus)) {
4911 if (Offset.isInvalid())
4913 Bound.
E = Offset.get();
4917 if (!Tok.isOneOf(tok::colon, tok::comma, tok::r_paren,
4918 tok::annot_pragma_openmp_end)) {
4919 Diag(Tok, diag::err_omp_num_args_invalid_form) << 1;
4927 bool IsError =
false;
4933 bool ItemError =
false;
4934 if (Tok.isNot(tok::colon)) {
4938 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
4943 if (Tok.is(tok::colon)) {
4947 if (!Tok.isOneOf(tok::comma, tok::r_paren,
4948 tok::annot_pragma_openmp_end)) {
4952 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
4959 Item.
Lower = LowerBound;
4960 Item.
Upper = UpperBound;
4961 Items.push_back(Item);
4963 }
else if (!ItemError &&
4968 Diag(ItemLoc, diag::err_omp_num_args_invalid_form) << 0;
4972 Item.
E = LowerBound.
E;
4973 Items.push_back(Item);
4979 if (Tok.isNot(tok::comma)) {
4980 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
4981 Diag(Tok, diag::err_omp_expected_punc)
4982 << getOpenMPClauseName(OMPC_adjust_args) << 0;
4984 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
4987 if (Tok.isNot(tok::comma))
5004 Data.DepModOrTailExpr = Tail.
get();
5006 if (CurTok.
isNot(tok::r_paren) && CurTok.
isNot(tok::comma)) {
5007 P.
Diag(CurTok, diag::err_expected_punc) <<
"step expression";
5025 bool AllocatorSeen =
false;
5026 bool AlignSeen =
false;
5045 if (
Tok.is(tok::l_paren)) {
5046 switch (CurrentModifier) {
5047 case OMPC_ALLOCATE_allocator: {
5048 if (AllocatorSeen) {
5049 P.
Diag(
Tok, diag::err_omp_duplicate_modifier)
5051 << getOpenMPClauseName(Kind);
5053 Data.AllocClauseModifiers.push_back(CurrentModifier);
5054 Data.AllocClauseModifiersLoc.push_back(CurrentModifierLoc);
5057 tok::annot_pragma_openmp_end);
5061 AllocatorSeen =
true;
5064 case OMPC_ALLOCATE_align: {
5066 P.
Diag(
Tok, diag::err_omp_duplicate_modifier)
5068 << getOpenMPClauseName(Kind);
5070 Data.AllocClauseModifiers.push_back(CurrentModifier);
5071 Data.AllocClauseModifiersLoc.push_back(CurrentModifierLoc);
5075 Data.AllocateAlignment = Val.
get();
5080 llvm_unreachable(
"Unexpected allocate modifier");
5083 P.
Diag(
Tok, diag::err_expected) << tok::l_paren;
5085 if (
Tok.isNot(tok::comma))
5088 CurrentModifierLoc =
Tok.getLocation();
5093 P.
Diag(
Tok, diag::err_omp_expected_modifier) << getOpenMPClauseName(Kind);
5096 }
while (!AllocatorSeen || !AlignSeen);
5105 bool InvalidReductionId =
false;
5106 bool IsInvalidMapperModifier =
false;
5110 if (
T.expectAndConsume(diag::err_expected_lparen_after,
5111 getOpenMPClauseName(Kind).data()))
5114 bool HasIterator =
false;
5115 bool InvalidIterator =
false;
5116 bool NeedRParenForLinear =
false;
5120 bool ParsedAdjustArgsList =
false;
5121 bool InvalidAdjustArgsList =
false;
5123 tok::annot_pragma_openmp_end);
5125 if (Kind == OMPC_reduction || Kind == OMPC_task_reduction ||
5126 Kind == OMPC_in_reduction) {
5128 if (Kind == OMPC_reduction &&
getLangOpts().OpenMP >= 50 &&
5129 (Tok.is(tok::identifier) || Tok.is(tok::kw_default)) &&
5132 Data.ExtraModifier =
5134 Data.ExtraModifierLoc = Tok.getLocation();
5136 assert(Tok.is(tok::comma) &&
"Expected comma.");
5140 if (Kind == OMPC_reduction &&
getLangOpts().OpenMP >= 60 &&
5141 Tok.is(tok::identifier) && PP.getSpelling(Tok) ==
"original" &&
5147 if (Tok.is(tok::kw_private)) {
5148 Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_private;
5149 Data.OriginalSharingModifierLoc = Tok.getLocation();
5151 }
else if (Tok.is(tok::identifier) &&
5152 (PP.getSpelling(Tok) ==
"shared" ||
5153 PP.getSpelling(Tok) ==
"default")) {
5154 Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_shared;
5155 Data.OriginalSharingModifierLoc = Tok.getLocation();
5158 Diag(Tok.getLocation(), diag::err_expected)
5159 <<
"'private or shared or default'";
5164 if (!Tok.is(tok::comma)) {
5165 Diag(Tok.getLocation(), diag::err_expected) <<
"',' (comma)";
5172 ParseOptionalCXXScopeSpecifier(
Data.ReductionOrMapperIdScopeSpec,
5177 *
this,
Data.ReductionOrMapperIdScopeSpec, UnqualifiedReductionId);
5178 if (InvalidReductionId) {
5179 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
5182 if (Tok.is(tok::colon))
5185 Diag(Tok, diag::warn_pragma_expected_colon) <<
"reduction identifier";
5186 if (!InvalidReductionId)
5187 Data.ReductionOrMapperId =
5188 Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId);
5189 }
else if (Kind == OMPC_depend || Kind == OMPC_doacross) {
5191 if (Tok.is(tok::identifier) && PP.getSpelling(Tok) ==
"iterator") {
5200 ExprResult IteratorRes = ParseOpenMPIteratorsExpr();
5201 Data.DepModOrTailExpr = IteratorRes.
get();
5203 ExpectAndConsume(tok::comma);
5209 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) :
"",
5211 Data.ExtraModifierLoc = Tok.getLocation();
5213 (Kind == OMPC_doacross &&
5215 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
5220 if (DKind == OMPD_ordered_standalone && Kind == OMPC_depend &&
5221 Data.ExtraModifier == OMPC_DEPEND_source) {
5227 if (Tok.is(tok::colon)) {
5229 }
else if (Kind != OMPC_doacross || Tok.isNot(tok::r_paren)) {
5230 Diag(Tok, DKind == OMPD_ordered_standalone
5231 ? diag::warn_pragma_expected_colon_r_paren
5232 : diag::warn_pragma_expected_colon)
5233 << (Kind == OMPC_depend ?
"dependency type" :
"dependence-type");
5235 if (Kind == OMPC_doacross) {
5236 if (Tok.is(tok::identifier) &&
5237 Tok.getIdentifierInfo()->isStr(
"omp_cur_iteration")) {
5238 Data.ExtraModifier =
Data.ExtraModifier == OMPC_DOACROSS_source
5239 ? OMPC_DOACROSS_source_omp_cur_iteration
5240 : OMPC_DOACROSS_sink_omp_cur_iteration;
5243 if (
Data.ExtraModifier == OMPC_DOACROSS_sink_omp_cur_iteration) {
5244 if (Tok.isNot(tok::minus)) {
5245 Diag(Tok, diag::err_omp_sink_and_source_iteration_not_allowd)
5246 << getOpenMPClauseName(Kind) << 0 << 0;
5253 if (Tok.isNot(tok::numeric_constant) ||
5254 (PP.parseSimpleIntegerLiteral(Tok,
Value) &&
Value != 1)) {
5255 Diag(Loc, diag::err_omp_sink_and_source_iteration_not_allowd)
5256 << getOpenMPClauseName(Kind) << 0 << 0;
5262 if (
Data.ExtraModifier == OMPC_DOACROSS_source_omp_cur_iteration) {
5263 if (Tok.isNot(tok::r_paren)) {
5264 Diag(Tok, diag::err_omp_sink_and_source_iteration_not_allowd)
5265 << getOpenMPClauseName(Kind) << 1 << 1;
5271 if (Kind == OMPC_doacross &&
5272 (
Data.ExtraModifier == OMPC_DOACROSS_source ||
5273 Data.ExtraModifier == OMPC_DOACROSS_source_omp_cur_iteration ||
5274 Data.ExtraModifier == OMPC_DOACROSS_sink_omp_cur_iteration)) {
5280 }
else if (Kind == OMPC_linear) {
5282 Data.ExtraModifier = OMPC_LINEAR_val;
5283 if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) {
5284 Data.ExtraModifier =
5288 NeedRParenForLinear =
true;
5290 Diag(
Data.ExtraModifierLoc, diag::err_omp_deprecate_old_syntax)
5291 <<
"linear-modifier(list)" << getOpenMPClauseName(Kind)
5292 <<
"linear(list: [linear-modifier,] step(step-size))";
5294 }
else if (Kind == OMPC_lastprivate) {
5301 Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::colon)) {
5302 Data.ExtraModifier =
5304 Data.ExtraModifierLoc = Tok.getLocation();
5306 assert(Tok.is(tok::colon) &&
"Expected colon.");
5309 }
else if (Kind == OMPC_map) {
5311 if (Tok.is(tok::identifier) && PP.getSpelling(Tok) ==
"iterator") {
5314 Data.MapTypeModifiers.push_back(OMPC_MAP_MODIFIER_iterator);
5315 Data.MapTypeModifiersLoc.push_back(Tok.getLocation());
5316 ExprResult IteratorRes = ParseOpenMPIteratorsExpr();
5317 Data.IteratorExpr = IteratorRes.
get();
5319 ExpectAndConsume(tok::comma);
5321 Diag(Tok, diag::err_omp_unknown_map_type_modifier)
5324 InvalidIterator =
true;
5334 Data.ExtraModifierLoc = Tok.getLocation();
5337 TentativeParsingAction TPA(*
this);
5338 bool ColonPresent =
false;
5339 if (
SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
5341 if (Tok.is(tok::colon))
5342 ColonPresent =
true;
5349 Diag(Tok, diag::err_omp_map_modifier_specification_list);
5351 if (
getLangOpts().OpenMP < 60 && !IsInvalidMapperModifier)
5357 Data.ExtraModifier = OMPC_MAP_tofrom;
5359 if (DKind == OMPD_target_enter_data)
5360 Data.ExtraModifier = OMPC_MAP_to;
5361 else if (DKind == OMPD_target_exit_data)
5362 Data.ExtraModifier = OMPC_MAP_from;
5364 Data.IsMapTypeImplicit =
true;
5367 if (Tok.is(tok::colon))
5369 }
else if (Kind == OMPC_to || Kind == OMPC_from) {
5370 while (Tok.is(tok::identifier)) {
5375 Data.MotionModifiers.push_back(Modifier);
5376 Data.MotionModifiersLoc.push_back(Tok.getLocation());
5377 if (PP.getSpelling(Tok) ==
"iterator" &&
getLangOpts().OpenMP >= 51) {
5379 Tail = ParseOpenMPIteratorsExpr();
5380 Tail = Actions.ActOnFinishFullExpr(Tail.
get(),
T.getOpenLocation(),
5383 Data.IteratorExpr = Tail.
get();
5386 if (Modifier == OMPC_MOTION_MODIFIER_mapper) {
5388 if (IsInvalidMapperModifier)
5396 if (Tok.is(tok::comma))
5400 if (!
Data.MotionModifiers.empty() && Tok.isNot(tok::colon)) {
5401 if (!IsInvalidMapperModifier) {
5403 Diag(Tok, diag::warn_pragma_expected_colon) <<
")";
5405 Diag(Tok, diag::warn_pragma_expected_colon) <<
"motion modifier";
5407 SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end,
5415 }
else if (Kind == OMPC_allocate ||
5416 (Kind == OMPC_affinity && Tok.is(tok::identifier) &&
5417 PP.getSpelling(Tok) ==
"iterator")) {
5421 TentativeParsingAction TPA(*
this);
5426 if (Kind == OMPC_allocate) {
5431 Tail = ParseOpenMPIteratorsExpr();
5433 Tail = Actions.ActOnFinishFullExpr(Tail.
get(),
T.getOpenLocation(),
5436 if (Tok.is(tok::colon)) {
5443 if (Kind == OMPC_allocate &&
Data.AllocClauseModifiers.size()) {
5444 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end,
5446 Diag(Tok, diag::err_modifier_expected_colon) <<
"allocate clause";
5453 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
5456 }
else if (Kind == OMPC_adjust_args) {
5460 Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) :
"",
5462 Data.ExtraModifierLoc = Tok.getLocation();
5464 Diag(Tok, diag::err_omp_unknown_adjust_args_op)
5469 if (Tok.is(tok::colon))
5470 Data.ColonLoc = Tok.getLocation();
5474 if (Tok.is(tok::l_paren)) {
5477 if (Tok.is(tok::identifier)) {
5478 std::string Modifier = PP.getSpelling(Tok);
5479 if (Modifier ==
"fb_nullify" || Modifier ==
"fb_preserve") {
5480 Data.NeedDevicePtrModifier =
5481 Modifier ==
"fb_nullify" ? OMPC_NEED_DEVICE_PTR_fb_nullify
5482 : OMPC_NEED_DEVICE_PTR_fb_preserve;
5484 Diag(Tok, diag::err_omp_unknown_need_device_ptr_kind);
5485 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end,
5490 if (Tok.is(tok::r_paren)) {
5491 Data.NeedDevicePtrModifierLoc = Tok.getLocation();
5494 Diag(Tok, diag::err_expected) << tok::r_paren;
5495 SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end,
5504 ExpectAndConsume(tok::colon, diag::warn_pragma_expected_colon,
5510 ParsedAdjustArgsList =
true;
5514 }
else if (Kind == OMPC_use_device_ptr) {
5518 if (
getLangOpts().OpenMP >= 61 && Tok.is(tok::identifier)) {
5522 Data.ExtraModifier = FallbackModifier;
5523 Data.ExtraModifierLoc = Tok.getLocation();
5525 if (Tok.is(tok::colon))
5528 Diag(Tok, diag::err_modifier_expected_colon) <<
"fallback";
5531 }
else if (Kind == OMPC_num_teams || Kind == OMPC_thread_limit) {
5535 Data.ExtraModifierArray[0] =
Data.ExtraModifierArray[1] =
5540 bool CanParseLowerBoundModifier = (Kind == OMPC_num_teams);
5541 if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->isStr(
"dims") &&
5548 Data.ExtraModifierArray[Mod] =
5549 Kind == OMPC_num_teams ?
static_cast<int>(OMPC_NUMTEAMS_dims)
5550 :
static_cast<int>(OMPC_THREADLIMIT_dims);
5551 Data.ExtraModifierExprArray[Mod] = ExprR.
get();
5552 Data.ExtraModifierLocArray[Mod] = TLoc;
5556 if (Tok.is(tok::colon)) {
5559 CanParseLowerBoundModifier =
false;
5560 }
else if (CanParseLowerBoundModifier && Tok.is(tok::comma)) {
5565 Diag(Tok, diag::err_modifier_expected_colon)
5566 << getOpenMPClauseName(Kind);
5568 Data.RLoc = Tok.getLocation();
5569 if (!
T.consumeClose())
5570 Data.RLoc =
T.getCloseLocation();
5576 if (CanParseLowerBoundModifier) {
5577 TentativeParsingAction TPA(*
this);
5582 Data.RLoc = Tok.getLocation();
5583 if (!
T.consumeClose())
5584 Data.RLoc =
T.getCloseLocation();
5589 if (Tok.is(tok::colon)) {
5592 Data.ExtraModifierArray[Mod] = OMPC_NUMTEAMS_lower_bound;
5593 Data.ExtraModifierExprArray[Mod] = FirstExpr.
get();
5594 Data.ExtraModifierLocArray[Mod] = TLoc;
5602 }
else if (Kind == OMPC_num_threads) {
5606 bool HasModifier =
false;
5608 if (Tok.is(tok::identifier) && Tok.getIdentifierInfo()->isStr(
"dims") &&
5619 Diag(TLoc, diag::err_omp_incompatible_modifiers)
5622 << getOpenMPClauseName(Kind);
5624 Data.ExtraModifierArray[1] =
static_cast<int>(OMPC_NUMTHREADS_dims);
5625 Data.ExtraModifierExprArray[1] =
5627 Data.ExtraModifierLocArray[1] = TLoc;
5634 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
5639 Diag(Tok, diag::err_omp_incompatible_modifiers)
5642 Data.ExtraModifierArray[0])
5643 << getOpenMPClauseName(Kind);
5644 Data.ExtraModifierArray[0] = Modifier;
5645 Data.ExtraModifierLocArray[0] = Tok.getLocation();
5655 if (Tok.is(tok::comma))
5663 if (!Tok.is(tok::colon)) {
5664 Diag(Tok, diag::err_modifier_expected_colon)
5665 << getOpenMPClauseName(Kind);
5667 Data.RLoc = Tok.getLocation();
5668 if (!
T.consumeClose())
5669 Data.RLoc =
T.getCloseLocation();
5677 (Kind != OMPC_reduction && Kind != OMPC_task_reduction &&
5678 Kind != OMPC_in_reduction && Kind != OMPC_depend &&
5679 Kind != OMPC_doacross && Kind != OMPC_map && Kind != OMPC_adjust_args) ||
5680 (Kind == OMPC_reduction && !InvalidReductionId) ||
5684 (Kind == OMPC_adjust_args &&
5686 const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned);
5687 while (!ParsedAdjustArgsList &&
5688 (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) &&
5689 Tok.isNot(tok::annot_pragma_openmp_end)))) {
5696 Vars.push_back(VarExpr.
get());
5698 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
5703 IsComma = Tok.is(tok::comma);
5706 else if (Tok.isNot(tok::r_paren) &&
5707 Tok.isNot(tok::annot_pragma_openmp_end) &&
5708 (!MayHaveTail || Tok.isNot(tok::colon))) {
5709 llvm::omp::Version OMPVersion = Actions.getLangOpts().getOpenMPVersion();
5710 Diag(Tok, diag::err_omp_expected_punc)
5711 << ((Kind == OMPC_flush)
5712 ? getOpenMPDirectiveName(OMPD_flush, OMPVersion)
5713 : getOpenMPClauseName(Kind))
5714 << (Kind == OMPC_flush);
5719 if (NeedRParenForLinear)
5723 const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon);
5724 bool StepFound =
false;
5725 bool ModifierFound =
false;
5727 Data.ColonLoc = Tok.getLocation();
5730 if (
getLangOpts().OpenMP >= 52 && Kind == OMPC_linear) {
5731 bool Malformed =
false;
5732 while (Tok.isNot(tok::r_paren)) {
5733 if (Tok.is(tok::identifier)) {
5738 Kind, Tok.isAnnotation() ?
"" : PP.getSpelling(Tok),
5741 if (LinKind == OMPC_LINEAR_step) {
5743 Diag(Tok, diag::err_omp_multiple_step_or_linear_modifier) << 0;
5746 tok::annot_pragma_openmp_end);
5750 Diag(StepModifierLoc, diag::err_expected_lparen_after) <<
"step";
5755 Data.StepModifierLoc = StepModifierLoc;
5759 }
else if (LinKind >= 0 && LinKind < OMPC_LINEAR_step) {
5761 Diag(Tok, diag::err_omp_multiple_step_or_linear_modifier) << 1;
5763 Data.ExtraModifier = LinKind;
5765 ModifierFound =
true;
5770 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
5779 if (Tok.is(tok::comma))
5781 if (Tok.is(tok::r_paren) || Tok.is(tok::annot_pragma_openmp_end))
5784 if (!Malformed && !StepFound && !ModifierFound)
5785 Diag(ELoc, diag::err_expected_expression);
5789 Tail = Actions.ActOnFinishFullExpr(Tail.
get(), ELoc,
5792 Data.DepModOrTailExpr = Tail.
get();
5794 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
5800 Data.RLoc = Tok.getLocation();
5801 if (!
T.consumeClose())
5802 Data.RLoc =
T.getCloseLocation();
5806 return (Kind != OMPC_depend && Kind != OMPC_doacross && Kind != OMPC_map &&
5807 Vars.empty() && AdjustArgsItems.empty()) ||
5808 (MustHaveTail && !
Data.DepModOrTailExpr && StepFound) ||
5809 InvalidReductionId || IsInvalidMapperModifier || InvalidIterator ||
5810 InvalidAdjustArgsList;
5838 "Expected parsing to start at clause name");
5843 if (
T.consumeOpen()) {
5844 Diag(
Tok, diag::err_expected) << tok::l_paren;
5857 Exprs.push_back(Val.
get());
5860 bool Result =
T.consumeClose();
5861 OpenLoc =
T.getOpenLocation();
5862 CloseLoc =
T.getCloseLocation();
Defines the clang::ASTContext interface.
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.
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
static OpenMPDirectiveKind checkOpenMPDirectiveName(Parser &P, SourceLocation Loc, OpenMPDirectiveKind Kind, StringRef Name)
static OpenMPDirectiveKind parseOpenMPDirectiveKind(Parser &P)
static OpenMPMapModifierKind isMapModifier(Parser &P)
Checks if the token is a valid map-type-modifier.
static std::optional< SimpleClauseData > parseOpenMPSimpleClause(Parser &P, OpenMPClauseKind Kind)
static bool checkExtensionProperty(Parser &P, SourceLocation Loc, OMPTraitProperty &TIProperty, OMPTraitSelector &TISelector, llvm::StringMap< SourceLocation > &Seen)
static ExprResult parseOpenMPAllocateClauseModifiers(Parser &P, OpenMPClauseKind Kind, SemaOpenMP::OpenMPVarListDataTy &Data)
Parse 'allocate' clause modifiers.
static DeclarationName parseOpenMPReductionId(Parser &P)
static ExprResult parseContextScore(Parser &P)
Parse optional 'score' '(' <expr> ')' ':'.
static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, UnqualifiedId &ReductionId)
static bool parseStepSize(Parser &P, SemaOpenMP::OpenMPVarListDataTy &Data, OpenMPClauseKind CKind, SourceLocation ELoc)
Parse step size expression.
static void parseMapType(Parser &P, SemaOpenMP::OpenMPVarListDataTy &Data)
Parse map-type in map clause.
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.
static OpenMPMapClauseKind isMapType(Parser &P)
Checks if the token is a valid map-type.
This file declares semantic analysis functions specific to AMDGPU.
This file declares facilities that support code completion.
This file declares semantic analysis for OpenMP constructs and clauses.
Defines the clang::TokenKind enum and support functions.
VerifyDiagnosticConsumer::Directive Directive
void getAsVariantMatchInfo(ASTContext &ASTCtx, llvm::omp::VariantMatchInfo &VMI) const
Create a variant match info object from this trait info object.
llvm::SmallVector< OMPTraitSet, 2 > Sets
The outermost level of selector sets.
bool anyScoreOrCondition(llvm::function_ref< bool(Expr *&, bool)> Cond)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
DeclarationNameTable DeclarationNames
OMPTraitInfo & getNewOMPTraitInfo()
Return a new OMPTraitInfo object owned by this context.
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
Represents a C++ nested-name-specifier or a global scope specifier.
bool isEmpty() const
No scope specifier.
static const TST TST_unspecified
Decl - This represents one declaration (or definition), e.g.
bool isFunctionOrFunctionTemplate() const
Whether this declaration is a function or function template.
SourceLocation getLocation() const
DeclContext * getDeclContext()
SourceLocation getBeginLoc() const LLVM_READONLY
The name of a declaration.
bool isEmpty() const
Evaluates true when this declaration name is empty.
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval=false) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
llvm::omp::Version getOpenMPVersion() const
Return the OpenMP version.
This represents a decl that may have a name.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
This is a basic class for representing single OpenMP clause.
static const ParsedAttributesView & none()
ParsedAttributes - A collection of parsed attributes.
Introduces zero or more scopes for parsing.
void Enter(unsigned ScopeFlags)
ParseScope - Introduces a new scope for parsing.
Parser - This implements a parser for the C family of languages.
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Preprocessor & getPreprocessor() const
bool parseMapTypeModifiers(SemaOpenMP::OpenMPVarListDataTy &Data)
Parse map-type-modifiers in map clause.
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
ParseStringLiteralExpression - This handles the various token types that form string literals,...
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
bool ParseOpenMPAdjustArgsList(SmallVectorImpl< OMPAdjustArgsItem > &Items)
Parses an OpenMP 6.0 'adjust_args' parameter list, whose items may be parameter names,...
Sema & getActions() const
void EnterScope(unsigned ScopeFlags)
EnterScope - Start a new scope.
bool parseMapperModifier(SemaOpenMP::OpenMPVarListDataTy &Data)
Parses the mapper modifier in map, to, and from clauses.
friend class ParsingOpenMPDirectiveRAII
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
friend class ColonProtectionRAIIObject
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Scope * getCurScope() const
bool ParseOpenMPVarList(OpenMPDirectiveKind DKind, OpenMPClauseKind Kind, SmallVectorImpl< Expr * > &Vars, SemaOpenMP::OpenMPVarListDataTy &Data, SmallVectorImpl< OMPAdjustArgsItem > &AdjustArgsItems)
Parses clauses with list.
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 ...
const Token & getCurToken() const
bool ParseOpenMPAdjustArgsBound(OMPAdjustArgsItem::Bound &Bound)
Parses one bound of an OpenMP 6.0 'adjust_args' parameter range, which may be 'omp_num_args' with an ...
void ExitScope()
ExitScope - Pop a scope off the scope stack.
ExprResult ParseOpenMPParensExpr(StringRef ClauseName, SourceLocation &RLoc, bool IsAddressOfOperand=false)
Parses simple expression in parens for single-expression clauses of OpenMP constructs.
const LangOptions & getLangOpts() const
friend class ParenBraceBracketBalancer
ExprResult ParseExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
bool ParseOpenMPReservedLocator(OpenMPClauseKind Kind, SemaOpenMP::OpenMPVarListDataTy &Data, const LangOptions &LangOpts)
Parses a reserved locator like 'omp_all_memory'.
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
ExprResult ParseAssignmentExpression(TypoCorrectionTypeBehavior CorrectionBehavior=TypoCorrectionTypeBehavior::AllowNonTypes)
Parse an expr that doesn't include (top-level) commas.
friend class BalancedDelimiterTracker
unsigned ReenterTemplateScopes(MultiParseScope &S, Decl *D)
Re-enter a possible template scope, creating as many template parameter scopes as necessary.
bool ParseOpenMPDeclareBeginVariantDirective(SourceLocation Loc)
Parses 'omp begin declare variant' directive.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
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 ...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
The collection of all-type qualifiers we support.
Represents a struct/union/class.
@ OpenMPDirectiveScope
This is the scope of OpenMP executable directive.
@ CompoundStmtScope
This is a compound statement scope.
@ OpenMPSimdDirectiveScope
This is the scope of some OpenMP simd directive.
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ OpenMPLoopDirectiveScope
This is the scope of some OpenMP loop directive.
@ DeclScope
This is a scope that can contain a declaration.
Smart pointer class that efficiently represents Objective-C method names.
bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, SourceLocation LinLoc)
Checks correctness of linear modifiers.
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef< Expr * > Vars, const OMPVarListLocTy &Locs, OpenMPVarListDataTy &Data)
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Sema - This implements semantic analysis and AST building for C.
Scope * getCurScope() const
Retrieve the parser's current scope.
void ActOnExitFunctionContext()
void ActOnReenterFunctionContext(Scope *S, Decl *D)
Push the parameters of D, which must be a function, into scope.
ASTContext & getASTContext() const
const LangOptions & getLangOpts() const
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
A trivial tuple used to represent a source range.
StringLiteral - This represents a string literal expression, e.g.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
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)) {....
tok::TokenKind getKind() const
bool isNot(tok::TokenKind K) const
Base wrapper for a particular "section" of type source info.
The base class of the type hierarchy.
QualType getCanonicalTypeInternal() const
Represents a C++ unqualified-id that has been parsed.
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
Represents a variable declaration or definition.
Defines the clang::TargetInfo interface.
PRESERVE_NONE bool Ret(InterpState &S)
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
Top level wrappers for InstallAPI frontend operations.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
@ OMPC_DEFAULTMAP_MODIFIER_unknown
@ OMPC_ORDER_MODIFIER_unknown
OpenMPNeedDevicePtrModifier
OpenMP 6.1 need_device modifier.
@ OMPC_NEED_DEVICE_PTR_unknown
OpenMPAdjustArgsOpKind
OpenMP adjust-op kinds for 'adjust_args' clause.
@ OMPC_ADJUST_ARGS_unknown
bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a distribute directive.
OpenMPDeviceType
OpenMP device type for 'device_type' clause.
@ OMPC_DEVICE_TYPE_unknown
@ OMPC_SCHEDULE_MODIFIER_unknown
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
const char * getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool isOpenMPTargetExecutionDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a target code offload directive.
@ OMPC_DYN_GROUPPRIVATE_FALLBACK_unknown
@ OMPC_DYN_GROUPPRIVATE_FALLBACK_last
@ Property
The type of a property.
@ Result
The result type of a method or function.
ActionResult< ParsedType > TypeResult
const FunctionProtoType * T
@ OMPC_LASTPRIVATE_unknown
OpenMPGrainsizeClauseModifier
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str, const LangOptions &LangOpts)
OpenMPNumTasksClauseModifier
OpenMPUseDevicePtrFallbackModifier
OpenMP 6.1 use_device_ptr fallback modifier.
@ OMPC_USE_DEVICE_PTR_FALLBACK_unknown
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
OpenMPMotionModifierKind
OpenMP modifier kind for 'to' or 'from' clause.
@ OMPC_MOTION_MODIFIER_unknown
@ OMPC_DEFAULTMAP_unknown
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
bool isOpenMPExecutableDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is considered as "executable".
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
@ OMPC_DYN_GROUPPRIVATE_unknown
bool isOpenMPInformationalDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is considered as "informational".
bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a simd directive.
@ OMPC_THREADLIMIT_unknown
OpenMPNumThreadsClauseModifier
@ OMPC_NUMTHREADS_unknown
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
OpenMPMapModifierKind
OpenMP modifier kind for 'map' clause.
@ OMPC_MAP_MODIFIER_unknown
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
ActionResult< Expr * > ExprResult
bool isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a taskloop directive.
ActionResult< Stmt * > StmtResult
OpenMPDefaultClauseVariableCategory getOpenMPDefaultVariableCategory(StringRef Str, const LangOptions &LangOpts)
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
int const char * function
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 unsigned
llvm::omp::TraitProperty Kind
StringRef RawString
The raw string as we parsed it. This is needed for the isa trait set (which accepts anything) and (la...
llvm::omp::TraitSelector Kind
SmallVector< OMPTraitProperty, 1 > Properties
SmallVector< OMPTraitSelector, 2 > Selectors
Clang specific specialization of the OMPContext to lookup target features.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
One bound of a parameter range.
Expr * E
The bound expression, or the logical offset for a NumArgs bound.
One item in an OpenMP 'adjust_args' parameter list.
Expr * E
A named parameter or positional expression for a Single item.
llvm::SmallVector< OMPInteropPref, 4 > Prefs
This structure contains most locations needed for by an OMPVarListClause.
std::optional< Expr * > Indirect
The directive with indirect clause.
OpenMPDirectiveKind Kind
The directive kind, begin declare target or declare target.
OMPDeclareTargetDeclAttr::DevTypeTy DT
The 'device_type' as parsed from the clause.
SourceLocation Loc
The directive location.
llvm::DenseMap< NamedDecl *, MapInfo > ExplicitlyMapped
Explicitly listed variables and functions in a 'to' or 'link' clause.
SourceLocation DeclIdentLoc
SourceLocation SecColonLoc
IdentifierInfo * DeclIdent
OMPIteratorExpr::IteratorRange Range
Data used for processing a list of variables in OpenMP clauses.
Data for list of allocators.
Expr * AllocatorTraits
Allocator traits.
SourceLocation LParenLoc
Locations of '(' and ')' symbols.
Expr * Allocator
Allocator.