Author: Krzysztof Parzyszek Date: 2024-08-18T10:25:52-05:00 New Revision: e05307f6633ca405834a4fd24d858ffb676c9170
URL: https://github.com/llvm/llvm-project/commit/e05307f6633ca405834a4fd24d858ffb676c9170 DIFF: https://github.com/llvm/llvm-project/commit/e05307f6633ca405834a4fd24d858ffb676c9170.diff LOG: [clang][OpenMP] Avoid multiple calls to getCurrentDirective in DSAChecker, NFC Added: Modified: clang/lib/Sema/SemaOpenMP.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 87d81dfaad601b..ac51bee29bc5b0 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3717,6 +3717,7 @@ namespace { class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { DSAStackTy *Stack; Sema &SemaRef; + OpenMPDirectiveKind DKind = OMPD_unknown; bool ErrorFound = false; bool TryCaptureCXXThisMembers = false; CapturedStmt *CS = nullptr; @@ -3748,7 +3749,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { // Try to capture inner this->member references to generate correct mappings // and diagnostics. if (TryCaptureCXXThisMembers || - (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && + (isOpenMPTargetExecutionDirective(DKind) && llvm::any_of(S->getInnermostCapturedStmt()->captures(), [](const CapturedStmt::Capture &C) { return C.capturesThis(); @@ -3818,7 +3819,6 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { return; SourceLocation ELoc = E->getExprLoc(); - OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); // The default(none) clause requires that each variable that is referenced // in the construct, and does not have a predetermined data-sharing // attribute, must have its data-sharing attribute explicitly determined @@ -3983,7 +3983,6 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) return; auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); - OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); if (auto *TE = dyn_cast<CXXThisExpr>(E->getBase()->IgnoreParenCasts())) { if (!FD) return; @@ -4065,8 +4064,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { if (isOpenMPTargetExecutionDirective(DKind)) { OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; if (!checkMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map, - Stack->getCurrentDirective(), - /*NoDiagnose=*/true)) + DKind, /*NoDiagnose=*/true)) return; const auto *VD = cast<ValueDecl>( CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl()); @@ -4119,8 +4117,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { // Skip analysis of arguments of implicitly defined map clause for target // directives. if (C && !((isa<OMPFirstprivateClause>(C) || isa<OMPMapClause>(C)) && - C->isImplicit() && - !isOpenMPTaskingDirective(Stack->getCurrentDirective()))) { + C->isImplicit() && !isOpenMPTaskingDirective(DKind))) { for (Stmt *CC : C->children()) { if (CC) Visit(CC); @@ -4169,7 +4166,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { VarDecl *VD = Cap.getCapturedVar(); // Do not try to map the variable if it or its sub-component was mapped // already. - if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && + if (isOpenMPTargetExecutionDirective(DKind) && Stack->checkMappableExprComponentListsForDecl( VD, /*CurrentRegionOnly=*/true, [](OMPClauseMappableExprCommon::MappableExprComponentListRef, @@ -4200,8 +4197,9 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) { + DKind = S->getCurrentDirective(); // Process declare target link variables for the target directives. - if (isOpenMPTargetExecutionDirective(S->getCurrentDirective())) { + if (isOpenMPTargetExecutionDirective(DKind)) { for (DeclRefExpr *E : Stack->getLinkGlobals()) Visit(E); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits