diff options
author | Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com> | 2025-05-09 07:41:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-09 07:41:54 -0500 |
commit | 6094080d27bc6dae4d85de207d4cf5586becf1aa (patch) | |
tree | a02d746cb4546064f68d7fbcf727a809a6b3682b /clang/lib/Sema/SemaOpenMP.cpp | |
parent | 4b29ee407e6466364d70f7962104561553ea89cc (diff) | |
download | llvm-6094080d27bc6dae4d85de207d4cf5586becf1aa.zip llvm-6094080d27bc6dae4d85de207d4cf5586becf1aa.tar.gz llvm-6094080d27bc6dae4d85de207d4cf5586becf1aa.tar.bz2 |
[clang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139115)
The OpenMP version is stored in language options in ASTContext. If the
context is not available, use the fallback version.
RFC:
https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 171 |
1 files changed, 106 insertions, 65 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 2534822..90437fc 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3069,6 +3069,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, const DeclarationNameInfo &Id, OpenMPDirectiveKind Kind) { ASTContext &Context = getASTContext(); + unsigned OMPVersion = getLangOpts().OpenMP; LookupResult Lookup(SemaRef, Id, Sema::LookupOrdinaryName); SemaRef.LookupParsedName(Lookup, CurScope, &ScopeSpec, /*ObjectType=*/QualType(), @@ -3106,7 +3107,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, // Variables must be file-scope, namespace-scope, or static block-scope. if (Kind == OMPD_threadprivate && !VD->hasGlobalStorage()) { Diag(Id.getLoc(), diag::err_omp_global_var_arg) - << getOpenMPDirectiveName(Kind) << !VD->isStaticLocal(); + << getOpenMPDirectiveName(Kind, OMPVersion) << !VD->isStaticLocal(); bool IsDecl = VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; Diag(VD->getLocation(), @@ -3123,7 +3124,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, if (CanonicalVD->getDeclContext()->isTranslationUnit() && !SemaRef.getCurLexicalContext()->isTranslationUnit()) { Diag(Id.getLoc(), diag::err_omp_var_scope) - << getOpenMPDirectiveName(Kind) << VD; + << getOpenMPDirectiveName(Kind, OMPVersion) << VD; bool IsDecl = VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; Diag(VD->getLocation(), @@ -3138,7 +3139,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, if (CanonicalVD->isStaticDataMember() && !CanonicalVD->getDeclContext()->Equals(SemaRef.getCurLexicalContext())) { Diag(Id.getLoc(), diag::err_omp_var_scope) - << getOpenMPDirectiveName(Kind) << VD; + << getOpenMPDirectiveName(Kind, OMPVersion) << VD; bool IsDecl = VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; Diag(VD->getLocation(), @@ -3155,7 +3156,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, !SemaRef.getCurLexicalContext()->Encloses( CanonicalVD->getDeclContext()))) { Diag(Id.getLoc(), diag::err_omp_var_scope) - << getOpenMPDirectiveName(Kind) << VD; + << getOpenMPDirectiveName(Kind, OMPVersion) << VD; bool IsDecl = VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; Diag(VD->getLocation(), @@ -3169,7 +3170,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, if (CanonicalVD->isLocalVarDecl() && CurScope && !SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), CurScope)) { Diag(Id.getLoc(), diag::err_omp_var_scope) - << getOpenMPDirectiveName(Kind) << VD; + << getOpenMPDirectiveName(Kind, OMPVersion) << VD; bool IsDecl = VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; Diag(VD->getLocation(), @@ -3184,7 +3185,7 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope, if (Kind == OMPD_threadprivate && VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { Diag(Id.getLoc(), diag::err_omp_var_used) - << getOpenMPDirectiveName(Kind) << VD; + << getOpenMPDirectiveName(Kind, OMPVersion) << VD; return ExprError(); } @@ -3266,8 +3267,10 @@ SemaOpenMP::CheckOMPThreadPrivateDecl(SourceLocation Loc, // OpenMP [2.9.2, Restrictions, C/C++, p.10] // A threadprivate variable must not have a reference type. if (VD->getType()->isReferenceType()) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(ILoc, diag::err_omp_ref_type_arg) - << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); + << getOpenMPDirectiveName(OMPD_threadprivate, OMPVersion) + << VD->getType(); bool IsDecl = VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; Diag(VD->getLocation(), @@ -3513,10 +3516,12 @@ void SemaOpenMP::ActOnOpenMPAssumesDirective(SourceLocation Loc, OpenMPDirectiveKind DKind, ArrayRef<std::string> Assumptions, bool SkippedClauses) { - if (!SkippedClauses && Assumptions.empty()) + if (!SkippedClauses && Assumptions.empty()) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(Loc, diag::err_omp_no_clause_for_directive) << llvm::omp::getAllAssumeClauseOptions() - << llvm::omp::getOpenMPDirectiveName(DKind); + << llvm::omp::getOpenMPDirectiveName(DKind, OMPVersion); + } auto *AA = OMPAssumeAttr::Create(getASTContext(), llvm::join(Assumptions, ","), Loc); @@ -3664,9 +3669,10 @@ static void reportOriginalDsa(Sema &SemaRef, const DSAStackTy *Stack, Reason = PDSA_LocalVarPrivate; } if (Reason != PDSA_Implicit) { + unsigned OMPVersion = SemaRef.getLangOpts().OpenMP; SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) << Reason << ReportHint - << getOpenMPDirectiveName(Stack->getCurrentDirective()); + << getOpenMPDirectiveName(Stack->getCurrentDirective(), OMPVersion); } else if (DVar.ImplicitDSALoc.isValid()) { SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) << getOpenMPClauseNameForDiag(DVar.CKind); @@ -4683,8 +4689,9 @@ StmtResult SemaOpenMP::ActOnOpenMPRegionEnd(StmtResult S, if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && OC->getNumForLoops()) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(OC->getBeginLoc(), diag::err_omp_ordered_simd) - << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); + << getOpenMPDirectiveName(DSAStack->getCurrentDirective(), OMPVersion); ErrorFound = true; } if (ErrorFound) { @@ -4764,8 +4771,9 @@ static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) return false; + unsigned OMPVersion = SemaRef.getLangOpts().OpenMP; SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) - << getOpenMPDirectiveName(CancelRegion); + << getOpenMPDirectiveName(CancelRegion, OMPVersion); return true; } @@ -4796,17 +4804,18 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, ArrayRef<OpenMPDirectiveKind> ParentLOC = getLeafOrCompositeConstructs(ParentRegion, LeafOrComposite); OpenMPDirectiveKind EnclosingConstruct = ParentLOC.back(); + unsigned OMPVersion = SemaRef.getLangOpts().OpenMP; - if (SemaRef.LangOpts.OpenMP >= 50 && Stack->isParentOrderConcurrent() && + if (OMPVersion >= 50 && Stack->isParentOrderConcurrent() && !isOpenMPOrderConcurrentNestableDirective(CurrentRegion, SemaRef.LangOpts)) { SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_order) - << getOpenMPDirectiveName(CurrentRegion); + << getOpenMPDirectiveName(CurrentRegion, OMPVersion); return true; } if (isOpenMPSimdDirective(ParentRegion) && - ((SemaRef.LangOpts.OpenMP <= 45 && CurrentRegion != OMPD_ordered) || - (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion != OMPD_ordered && + ((OMPVersion <= 45 && CurrentRegion != OMPD_ordered) || + (OMPVersion >= 50 && CurrentRegion != OMPD_ordered && CurrentRegion != OMPD_simd && CurrentRegion != OMPD_atomic && CurrentRegion != OMPD_scan))) { // OpenMP [2.16, Nesting of Regions] @@ -4824,7 +4833,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) ? diag::err_omp_prohibited_region_simd : diag::warn_omp_nesting_simd) - << (SemaRef.LangOpts.OpenMP >= 50 ? 1 : 0); + << (OMPVersion >= 50 ? 1 : 0); return CurrentRegion != OMPD_simd; } if (EnclosingConstruct == OMPD_atomic) { @@ -4841,7 +4850,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, if (EnclosingConstruct != OMPD_sections) { SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) << (ParentRegion != OMPD_unknown) - << getOpenMPDirectiveName(ParentRegion); + << getOpenMPDirectiveName(ParentRegion, OMPVersion); return true; } return false; @@ -4856,14 +4865,14 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, return false; // Checks needed for mapping "loop" construct. Please check mapLoopConstruct // for a detailed explanation - if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop && + if (OMPVersion >= 50 && CurrentRegion == OMPD_loop && (BindKind == OMPC_BIND_parallel || BindKind == OMPC_BIND_teams) && (isOpenMPWorksharingDirective(ParentRegion) || EnclosingConstruct == OMPD_loop)) { int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4; SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) - << true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber - << getOpenMPDirectiveName(CurrentRegion); + << true << getOpenMPDirectiveName(ParentRegion, OMPVersion) + << ErrorMsgNumber << getOpenMPDirectiveName(CurrentRegion, OMPVersion); return true; } if (CurrentRegion == OMPD_cancellation_point || @@ -4881,9 +4890,9 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, // construct-type-clause. ArrayRef<OpenMPDirectiveKind> Leafs = getLeafConstructsOrSelf(ParentRegion); if (CancelRegion == OMPD_taskgroup) { - NestingProhibited = EnclosingConstruct != OMPD_task && - (SemaRef.getLangOpts().OpenMP < 50 || - EnclosingConstruct != OMPD_taskloop); + NestingProhibited = + EnclosingConstruct != OMPD_task && + (OMPVersion < 50 || EnclosingConstruct != OMPD_taskloop); } else if (CancelRegion == OMPD_sections) { NestingProhibited = EnclosingConstruct != OMPD_section && EnclosingConstruct != OMPD_sections; @@ -4969,13 +4978,13 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, // If specified, a teams construct must be contained within a target // construct. NestingProhibited = - (SemaRef.LangOpts.OpenMP <= 45 && EnclosingConstruct != OMPD_target) || - (SemaRef.LangOpts.OpenMP >= 50 && EnclosingConstruct != OMPD_unknown && + (OMPVersion <= 45 && EnclosingConstruct != OMPD_target) || + (OMPVersion >= 50 && EnclosingConstruct != OMPD_unknown && EnclosingConstruct != OMPD_target); OrphanSeen = ParentRegion == OMPD_unknown; Recommend = ShouldBeInTargetRegion; } else if (CurrentRegion == OMPD_scan) { - if (SemaRef.LangOpts.OpenMP >= 50) { + if (OMPVersion >= 50) { // OpenMP spec 5.0 and 5.1 require scan to be directly enclosed by for, // simd, or for simd. This has to take into account combined directives. // In 5.2 this seems to be implied by the fact that the specified @@ -5045,11 +5054,11 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, if (NestingProhibited) { if (OrphanSeen) { SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) - << getOpenMPDirectiveName(CurrentRegion) << Recommend; + << getOpenMPDirectiveName(CurrentRegion, OMPVersion) << Recommend; } else { SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) - << CloseNesting << getOpenMPDirectiveName(OffendingRegion) - << Recommend << getOpenMPDirectiveName(CurrentRegion); + << CloseNesting << getOpenMPDirectiveName(OffendingRegion, OMPVersion) + << Recommend << getOpenMPDirectiveName(CurrentRegion, OMPVersion); } return true; } @@ -5068,6 +5077,7 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, llvm::IndexedMap<const OMPIfClause *, Kind2Unsigned> FoundNameModifiers; FoundNameModifiers.resize(llvm::omp::Directive_enumSize + 1); SmallVector<SourceLocation, 4> NameModifierLoc; + unsigned OMPVersion = S.getLangOpts().OpenMP; for (const OMPClause *C : Clauses) { if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { // At most one if clause without a directive-name-modifier can appear on @@ -5076,9 +5086,9 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, auto &FNM = FoundNameModifiers[CurNM]; if (FNM) { S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) - << getOpenMPDirectiveName(Kind) + << getOpenMPDirectiveName(Kind, OMPVersion) << getOpenMPClauseNameForDiag(OMPC_if) << (CurNM != OMPD_unknown) - << getOpenMPDirectiveName(CurNM); + << getOpenMPDirectiveName(CurNM, OMPVersion); ErrorFound = true; } else if (CurNM != OMPD_unknown) { NameModifierLoc.push_back(IC->getNameModifierLoc()); @@ -5094,7 +5104,8 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, if (!llvm::is_contained(AllowedNameModifiers, CurNM)) { S.Diag(IC->getNameModifierLoc(), diag::err_omp_wrong_if_directive_name_modifier) - << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); + << getOpenMPDirectiveName(CurNM, OMPVersion) + << getOpenMPDirectiveName(Kind, OMPVersion); ErrorFound = true; } } @@ -5116,7 +5127,7 @@ static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; if (!FoundNameModifiers[NM]) { Values += "'"; - Values += getOpenMPDirectiveName(NM); + Values += getOpenMPDirectiveName(NM, OMPVersion); Values += "'"; if (AllowedCnt + 2 == TotalAllowedNum) Values += " or "; @@ -5320,9 +5331,10 @@ static void checkAllocateClauses(Sema &S, DSAStackTy *Stack, if (AllocatorKind == OMPAllocateDeclAttr::OMPThreadMemAlloc && (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()))) { + unsigned OMPVersion = S.getLangOpts().OpenMP; S.Diag(AC->getAllocator()->getExprLoc(), diag::warn_omp_allocate_thread_on_task_target_directive) - << getOpenMPDirectiveName(Stack->getCurrentDirective()); + << getOpenMPDirectiveName(Stack->getCurrentDirective(), OMPVersion); } for (Expr *E : AC->varlist()) { SourceLocation ELoc; @@ -9138,9 +9150,10 @@ void SemaOpenMP::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && (DVar.CKind != OMPC_private || DVar.RefExpr)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(Init->getBeginLoc(), diag::err_omp_loop_var_dsa) << getOpenMPClauseNameForDiag(DVar.CKind) - << getOpenMPDirectiveName(DKind) + << getOpenMPDirectiveName(DKind, OMPVersion) << getOpenMPClauseNameForDiag(PredeterminedCKind); if (DVar.RefExpr == nullptr) DVar.CKind = PredeterminedCKind; @@ -9195,9 +9208,10 @@ static bool checkOpenMPIterationSpace( auto *CXXFor = dyn_cast_or_null<CXXForRangeStmt>(S); // Ranged for is supported only in OpenMP 5.0. if (!For && (SemaRef.LangOpts.OpenMP <= 45 || !CXXFor)) { + unsigned OMPVersion = SemaRef.getLangOpts().OpenMP; SemaRef.Diag(S->getBeginLoc(), diag::err_omp_not_for) << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) - << getOpenMPDirectiveName(DKind) << TotalNestedLoopCount + << getOpenMPDirectiveName(DKind, OMPVersion) << TotalNestedLoopCount << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; if (TotalNestedLoopCount > 1) { if (CollapseLoopCountExpr && OrderedLoopCountExpr) @@ -10482,6 +10496,7 @@ static bool checkSectionsDirective(Sema &SemaRef, OpenMPDirectiveKind DKind, return true; assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); + unsigned OMPVersion = SemaRef.getLangOpts().OpenMP; auto BaseStmt = AStmt; while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) BaseStmt = CS->getCapturedStmt(); @@ -10496,7 +10511,7 @@ static bool checkSectionsDirective(Sema &SemaRef, OpenMPDirectiveKind DKind, if (SectionStmt) SemaRef.Diag(SectionStmt->getBeginLoc(), diag::err_omp_sections_substmt_not_section) - << getOpenMPDirectiveName(DKind); + << getOpenMPDirectiveName(DKind, OMPVersion); return true; } cast<OMPSectionDirective>(SectionStmt) @@ -10504,7 +10519,7 @@ static bool checkSectionsDirective(Sema &SemaRef, OpenMPDirectiveKind DKind, } } else { SemaRef.Diag(AStmt->getBeginLoc(), diag::err_omp_sections_not_compound_stmt) - << getOpenMPDirectiveName(DKind); + << getOpenMPDirectiveName(DKind, OMPVersion); return true; } return false; @@ -10609,8 +10624,9 @@ static bool checkGenericLoopLastprivate(Sema &S, ArrayRef<OMPClause *> Clauses, if (ValueDecl *D = Res.first) { auto &&Info = Stack->isLoopControlVariable(D); if (!Info.first) { + unsigned OMPVersion = S.getLangOpts().OpenMP; S.Diag(ELoc, diag::err_omp_lastprivate_loop_var_non_loop_iteration) - << getOpenMPDirectiveName(K); + << getOpenMPDirectiveName(K, OMPVersion); ErrorFound = true; } } @@ -11114,6 +11130,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, else OrderClause = C; } + unsigned OMPVersion = getLangOpts().OpenMP; OpenMPClauseKind MemOrderKind = OMPC_unknown; SourceLocation MemOrderLoc; for (const OMPClause *C : Clauses) { @@ -11123,7 +11140,7 @@ StmtResult SemaOpenMP::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, C->getClauseKind() == OMPC_seq_cst /*OpenMP 5.1*/) { if (MemOrderKind != OMPC_unknown) { Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses) - << getOpenMPDirectiveName(OMPD_flush) << 1 + << getOpenMPDirectiveName(OMPD_flush, OMPVersion) << 1 << SourceRange(C->getBeginLoc(), C->getEndLoc()); Diag(MemOrderLoc, diag::note_omp_previous_mem_order_clause) << getOpenMPClauseNameForDiag(MemOrderKind); @@ -11178,9 +11195,11 @@ StmtResult SemaOpenMP::ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, if (Scope *S = DSAStack->getCurScope()) { Scope *ParentS = S->getParent(); if (!ParentS || ParentS->getParent() != ParentS->getBreakParent() || - !ParentS->getBreakParent()->isOpenMPLoopScope()) + !ParentS->getBreakParent()->isOpenMPLoopScope()) { + unsigned OMPVersion = getLangOpts().OpenMP; return StmtError(Diag(StartLoc, diag::err_omp_orphaned_device_directive) - << getOpenMPDirectiveName(OMPD_scan) << 5); + << getOpenMPDirectiveName(OMPD_scan, OMPVersion) << 5); + } } // Check that only one instance of scan directives is used in the same outer // region. @@ -11218,8 +11237,9 @@ SemaOpenMP::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, if ((DC && DC->getDependencyKind() == OMPC_DEPEND_source) || (DOC && (ODK.isSource(DOC)))) { if ((DC && DependSourceClause) || (DOC && DoacrossSourceClause)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) - << getOpenMPDirectiveName(OMPD_ordered) + << getOpenMPDirectiveName(OMPD_ordered, OMPVersion) << getOpenMPClauseNameForDiag(DC ? OMPC_depend : OMPC_doacross) << 2; ErrorFound = true; @@ -12374,6 +12394,7 @@ StmtResult SemaOpenMP::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, SourceLocation StartLoc, SourceLocation EndLoc) { ASTContext &Context = getASTContext(); + unsigned OMPVersion = getLangOpts().OpenMP; // Register location of the first atomic directive. DSAStack->addAtomicDirectiveLoc(StartLoc); if (!AStmt) @@ -12433,7 +12454,7 @@ StmtResult SemaOpenMP::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, case OMPC_relaxed: { if (MemOrderKind != OMPC_unknown) { Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses) - << getOpenMPDirectiveName(OMPD_atomic) << 0 + << getOpenMPDirectiveName(OMPD_atomic, OMPVersion) << 0 << SourceRange(C->getBeginLoc(), C->getEndLoc()); Diag(MemOrderLoc, diag::note_omp_previous_mem_order_clause) << getOpenMPClauseNameForDiag(MemOrderKind); @@ -13091,8 +13112,9 @@ SemaOpenMP::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, Expected = "'map' or 'use_device_ptr'"; else Expected = "'map', 'use_device_ptr', or 'use_device_addr'"; + unsigned OMPVersion = getLangOpts().OpenMP; Diag(StartLoc, diag::err_omp_no_clause_for_directive) - << Expected << getOpenMPDirectiveName(OMPD_target_data); + << Expected << getOpenMPDirectiveName(OMPD_target_data, OMPVersion); return StmtError(); } @@ -13113,8 +13135,10 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetEnterDataDirective( // OpenMP [2.10.2, Restrictions, p. 99] // At least one map clause must appear on the directive. if (!hasClauses(Clauses, OMPC_map)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(StartLoc, diag::err_omp_no_clause_for_directive) - << "'map'" << getOpenMPDirectiveName(OMPD_target_enter_data); + << "'map'" + << getOpenMPDirectiveName(OMPD_target_enter_data, OMPVersion); return StmtError(); } @@ -13133,8 +13157,9 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetExitDataDirective( // OpenMP [2.10.3, Restrictions, p. 102] // At least one map clause must appear on the directive. if (!hasClauses(Clauses, OMPC_map)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(StartLoc, diag::err_omp_no_clause_for_directive) - << "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data); + << "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data, OMPVersion); return StmtError(); } @@ -17107,9 +17132,10 @@ SemaOpenMP::ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses, // OpenMP 5.1 [2.15.1, interop Construct, Restrictions] // At least one action-clause must appear on a directive. if (!hasClauses(Clauses, OMPC_init, OMPC_use, OMPC_destroy, OMPC_nowait)) { + unsigned OMPVersion = getLangOpts().OpenMP; StringRef Expected = "'init', 'use', 'destroy', or 'nowait'"; Diag(StartLoc, diag::err_omp_no_clause_for_directive) - << Expected << getOpenMPDirectiveName(OMPD_interop); + << Expected << getOpenMPDirectiveName(OMPD_interop, OMPVersion); return StmtError(); } @@ -17276,9 +17302,10 @@ OMPClause *SemaOpenMP::ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation EndLoc) { if (!InteropVar && getLangOpts().OpenMP >= 52 && DSAStack->getCurrentDirective() == OMPD_depobj) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(StartLoc, diag::err_omp_expected_clause_argument) << getOpenMPClauseNameForDiag(OMPC_destroy) - << getOpenMPDirectiveName(OMPD_depobj); + << getOpenMPDirectiveName(OMPD_depobj, OMPVersion); return nullptr; } if (InteropVar && @@ -17620,6 +17647,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, SourceLocation EndLoc) { SmallVector<Expr *, 8> Vars; SmallVector<Expr *, 8> PrivateCopies; + unsigned OMPVersion = getLangOpts().OpenMP; bool IsImplicitClause = StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); for (Expr *RefExpr : VarList) { @@ -17681,7 +17709,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, isOpenMPTaskingDirective(CurrDir)) { Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) << getOpenMPClauseNameForDiag(OMPC_private) << Type - << getOpenMPDirectiveName(CurrDir); + << getOpenMPDirectiveName(CurrDir, OMPVersion); bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) == VarDecl::DeclarationOnly; Diag(D->getLocation(), @@ -17712,7 +17740,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) << getOpenMPClauseNameForDiag(OMPC_private) << getOpenMPClauseNameForDiag(ConflictKind) - << getOpenMPDirectiveName(CurrDir); + << getOpenMPDirectiveName(CurrDir, OMPVersion); reportOriginalDsa(SemaRef, DSAStack, D, DVar); continue; } @@ -17774,6 +17802,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, bool IsImplicitClause = StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); SourceLocation ImplicitClauseLoc = DSAStack->getConstructLoc(); + unsigned OMPVersion = getLangOpts().OpenMP; for (Expr *RefExpr : VarList) { assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); @@ -17915,7 +17944,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, isOpenMPWorksharingDirective(DVar.DKind) || isOpenMPTeamsDirective(DVar.DKind))) { Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) - << getOpenMPDirectiveName(DVar.DKind); + << getOpenMPDirectiveName(DVar.DKind, OMPVersion); reportOriginalDsa(SemaRef, DSAStack, D, DVar); continue; } @@ -17944,7 +17973,8 @@ OMPClause *SemaOpenMP::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) << getOpenMPClauseNameForDiag(OMPC_firstprivate) << getOpenMPClauseNameForDiag(ConflictKind) - << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); + << getOpenMPDirectiveName(DSAStack->getCurrentDirective(), + OMPVersion); reportOriginalDsa(SemaRef, DSAStack, D, DVar); continue; } @@ -17956,7 +17986,8 @@ OMPClause *SemaOpenMP::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) << getOpenMPClauseNameForDiag(OMPC_firstprivate) << Type - << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); + << getOpenMPDirectiveName(DSAStack->getCurrentDirective(), + OMPVersion); bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) == VarDecl::DeclarationOnly; Diag(D->getLocation(), @@ -20009,9 +20040,10 @@ OMPClause *SemaOpenMP::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] // A list item that appears in a copyin clause must be threadprivate. if (!DSAStack->isThreadPrivate(VD)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(ELoc, diag::err_omp_required_access) << getOpenMPClauseNameForDiag(OMPC_copyin) - << getOpenMPDirectiveName(OMPD_threadprivate); + << getOpenMPDirectiveName(OMPD_threadprivate, OMPVersion); continue; } @@ -20118,9 +20150,11 @@ OMPClause *SemaOpenMP::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, // Variably modified types are not supported. if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) << getOpenMPClauseNameForDiag(OMPC_copyprivate) << Type - << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); + << getOpenMPDirectiveName(DSAStack->getCurrentDirective(), + OMPVersion); bool IsDecl = !VD || VD->isThisDeclarationADefinition(getASTContext()) == VarDecl::DeclarationOnly; Diag(D->getLocation(), @@ -21692,6 +21726,7 @@ static void checkMappableExpressionList( // We only expect mappable expressions in 'to', 'from', and 'map' clauses. assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && "Unexpected clause kind with mappable expressions!"); + unsigned OMPVersion = SemaRef.getLangOpts().OpenMP; // If the identifier of user-defined mapper is not specified, it is "default". // We do not change the actual name in this clause to distinguish whether a @@ -21896,7 +21931,7 @@ static void checkMappableExpressionList( SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) << (IsMapTypeImplicit ? 1 : 0) << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) - << getOpenMPDirectiveName(DKind); + << getOpenMPDirectiveName(DKind, OMPVersion); continue; } @@ -21911,7 +21946,7 @@ static void checkMappableExpressionList( SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) << (IsMapTypeImplicit ? 1 : 0) << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) - << getOpenMPDirectiveName(DKind); + << getOpenMPDirectiveName(DKind, OMPVersion); continue; } @@ -21926,7 +21961,7 @@ static void checkMappableExpressionList( diag::err_omp_invalid_map_type_modifier_for_directive) << getOpenMPSimpleClauseTypeName(OMPC_map, OMPC_MAP_MODIFIER_ompx_hold) - << getOpenMPDirectiveName(DKind); + << getOpenMPDirectiveName(DKind, OMPVersion); continue; } @@ -21941,7 +21976,7 @@ static void checkMappableExpressionList( SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) << (IsMapTypeImplicit ? 1 : 0) << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) - << getOpenMPDirectiveName(DKind); + << getOpenMPDirectiveName(DKind, OMPVersion); continue; } @@ -21961,7 +21996,8 @@ static void checkMappableExpressionList( SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) << getOpenMPClauseNameForDiag(DVar.CKind) << getOpenMPClauseNameForDiag(OMPC_map) - << getOpenMPDirectiveName(DSAS->getCurrentDirective()); + << getOpenMPDirectiveName(DSAS->getCurrentDirective(), + OMPVersion); reportOriginalDsa(SemaRef, DSAS, CurDeclaration, DVar); continue; } @@ -22900,8 +22936,9 @@ void SemaOpenMP::DiagnoseUnterminatedOpenMPDeclareTarget() { if (DeclareTargetNesting.empty()) return; DeclareTargetContextInfo &DTCI = DeclareTargetNesting.back(); + unsigned OMPVersion = getLangOpts().OpenMP; Diag(DTCI.Loc, diag::warn_omp_unterminated_declare_target) - << getOpenMPDirectiveName(DTCI.Kind); + << getOpenMPDirectiveName(DTCI.Kind, OMPVersion); } NamedDecl *SemaOpenMP::lookupOpenMPDeclareTargetName( @@ -23416,10 +23453,12 @@ SemaOpenMP::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, // sharing attribute. DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); if (isOpenMPPrivate(DVar.CKind)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) << getOpenMPClauseNameForDiag(DVar.CKind) << getOpenMPClauseNameForDiag(OMPC_is_device_ptr) - << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); + << getOpenMPDirectiveName(DSAStack->getCurrentDirective(), + OMPVersion); reportOriginalDsa(SemaRef, DSAStack, D, DVar); continue; } @@ -23492,10 +23531,12 @@ SemaOpenMP::ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, // sharing attribute. DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); if (isOpenMPPrivate(DVar.CKind)) { + unsigned OMPVersion = getLangOpts().OpenMP; Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) << getOpenMPClauseNameForDiag(DVar.CKind) << getOpenMPClauseNameForDiag(OMPC_has_device_addr) - << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); + << getOpenMPDirectiveName(DSAStack->getCurrentDirective(), + OMPVersion); reportOriginalDsa(SemaRef, DSAStack, D, DVar); continue; } |