Author: Timm Bäder Date: 2023-06-27T11:38:41+02:00 New Revision: 173df3dd5f9a812b07f9866965f4e92a982a3fca
URL: https://github.com/llvm/llvm-project/commit/173df3dd5f9a812b07f9866965f4e92a982a3fca DIFF: https://github.com/llvm/llvm-project/commit/173df3dd5f9a812b07f9866965f4e92a982a3fca.diff LOG: [clang][CFG][NFC] A few smaller cleanups Use dyn_cast_if_present instead of _or_null, use decomposition decls, and a few other minor things. Added: Modified: clang/lib/Analysis/CFG.cpp clang/lib/Analysis/ThreadSafety.cpp Removed: ################################################################################ diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 246bace4debcf..318b0af86ab70 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1560,7 +1560,7 @@ std::unique_ptr<CFG> CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) { "AddImplicitDtors and AddLifetime cannot be used at the same time"); if (BuildOpts.AddImplicitDtors) - if (const CXXDestructorDecl *DD = dyn_cast_or_null<CXXDestructorDecl>(D)) + if (const CXXDestructorDecl *DD = dyn_cast_if_present<CXXDestructorDecl>(D)) addImplicitDtorsForDestructor(DD); // Visit the statements and create the CFG. @@ -1581,7 +1581,7 @@ std::unique_ptr<CFG> CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) { // fields. To handle this, make a CFG branch. We only need to add one such // branch per constructor, since the Standard states that all virtual bases // shall be initialized before non-virtual bases and direct data members. - if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(D)) { + if (const auto *CD = dyn_cast_if_present<CXXConstructorDecl>(D)) { CFGBlock *VBaseSucc = nullptr; for (auto *I : llvm::reverse(CD->inits())) { if (BuildOpts.AddVirtualBaseBranches && !VBaseSucc && @@ -3010,7 +3010,7 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { // If the initializer is an ArrayInitLoopExpr, we want to extract the // initializer, that's used for each element. - const auto *AILE = dyn_cast_or_null<ArrayInitLoopExpr>(Init); + const auto *AILE = dyn_cast_if_present<ArrayInitLoopExpr>(Init); findConstructionContexts( ConstructionContextLayer::create(cfg->getBumpVectorContext(), DS), @@ -3591,7 +3591,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { // Specially handle logical operators, which have a slightly // more optimal CFG representation. if (BinaryOperator *Cond = - dyn_cast_or_null<BinaryOperator>(C ? C->IgnoreParens() : nullptr)) + dyn_cast_if_present<BinaryOperator>(C ? C->IgnoreParens() : nullptr)) if (Cond->isLogicalOp()) { std::tie(EntryConditionBlock, ExitConditionBlock) = VisitLogicalOperator(Cond, F, BodyBlock, LoopSuccessor); @@ -5383,7 +5383,7 @@ bool CFGBlock::FilterEdge(const CFGBlock::FilterOptions &F, // If the 'To' has no label or is labeled but the label isn't a // CaseStmt then filter this edge. if (const SwitchStmt *S = - dyn_cast_or_null<SwitchStmt>(From->getTerminatorStmt())) { + dyn_cast_if_present<SwitchStmt>(From->getTerminatorStmt())) { if (S->isAllEnumCasesCovered()) { const Stmt *L = To->getLabel(); if (!L || !isa<CaseStmt>(L)) diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 087994e6ebd70..1dc35edded70b 100644 --- a/clang/lib/Analysis/ThreadSafety.cpp +++ b/clang/lib/Analysis/ThreadSafety.cpp @@ -608,7 +608,7 @@ void VarMapBuilder::VisitDeclStmt(const DeclStmt *S) { bool modifiedCtx = false; const DeclGroupRef DGrp = S->getDeclGroup(); for (const auto *D : DGrp) { - if (const auto *VD = dyn_cast_or_null<VarDecl>(D)) { + if (const auto *VD = dyn_cast_if_present<VarDecl>(D)) { const Expr *E = VD->getInit(); // Add local variables with trivial type to the variable map @@ -1347,9 +1347,9 @@ void ThreadSafetyAnalyzer::getMutexIDs(CapExprSet &Mtxs, AttrType *Attr, Expr *BrE, bool Neg) { // Find out which branch has the lock bool branch = false; - if (const auto *BLE = dyn_cast_or_null<CXXBoolLiteralExpr>(BrE)) + if (const auto *BLE = dyn_cast_if_present<CXXBoolLiteralExpr>(BrE)) branch = BLE->getValue(); - else if (const auto *ILE = dyn_cast_or_null<IntegerLiteral>(BrE)) + else if (const auto *ILE = dyn_cast_if_present<IntegerLiteral>(BrE)) branch = ILE->getValue().getBoolValue(); int branchnum = branch ? 0 : 1; @@ -1472,7 +1472,7 @@ void ThreadSafetyAnalyzer::getEdgeLockset(FactSet& Result, if (!Exp) return; - auto *FunDecl = dyn_cast_or_null<NamedDecl>(Exp->getCalleeDecl()); + auto *FunDecl = dyn_cast_if_present<NamedDecl>(Exp->getCalleeDecl()); if(!FunDecl || !FunDecl->hasAttrs()) return; @@ -1787,15 +1787,15 @@ void BuildLockset::handleCall(const Expr *Exp, const NamedDecl *D, assert(!Self); const auto *TagT = Exp->getType()->getAs<TagType>(); if (TagT && Exp->isPRValue()) { - std::pair<til::LiteralPtr *, StringRef> Placeholder = + auto [ThisPtr, DiagType] = Analyzer->SxBuilder.createThisPlaceholder(Exp); [[maybe_unused]] auto inserted = - ConstructedObjects.insert({Exp, Placeholder.first}); + ConstructedObjects.insert({Exp, ThisPtr}); assert(inserted.second && "Are we visiting the same expression again?"); if (isa<CXXConstructExpr>(Exp)) - Self = Placeholder.first; + Self = ThisPtr; if (TagT->getDecl()->hasAttr<ScopedLockableAttr>()) - Scp = CapabilityExpr(Placeholder.first, Placeholder.second, false); + Scp = CapabilityExpr(ThisPtr, DiagType, false); } assert(Loc.isInvalid()); @@ -2098,7 +2098,7 @@ void BuildLockset::VisitDeclStmt(const DeclStmt *S) { LVarCtx = Analyzer->LocalVarMap.getNextContext(CtxIndex, S, LVarCtx); for (auto *D : S->getDeclGroup()) { - if (auto *VD = dyn_cast_or_null<VarDecl>(D)) { + if (auto *VD = dyn_cast_if_present<VarDecl>(D)) { const Expr *E = VD->getInit(); if (!E) continue; @@ -2215,10 +2215,10 @@ static bool neverReturns(const CFGBlock *B) { return false; CFGElement Last = B->back(); - if (std::optional<CFGStmt> S = Last.getAs<CFGStmt>()) { - if (isa<CXXThrowExpr>(S->getStmt())) - return true; - } + if (std::optional<CFGStmt> S = Last.getAs<CFGStmt>(); + isa<CXXThrowExpr>(S->getStmt())) + return true; + return false; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits