diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 318b0af86ab70..246bace4debcf 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1560,7 +1560,7 @@ std::unique_ptr 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_if_present(D)) + if (const CXXDestructorDecl *DD = dyn_cast_or_null(D)) addImplicitDtorsForDestructor(DD); // Visit the statements and create the CFG. @@ -1581,7 +1581,7 @@ std::unique_ptr 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_if_present(D)) { + if (const auto *CD = dyn_cast_or_null(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_if_present(Init); + const auto *AILE = dyn_cast_or_null(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_if_present(C ? C->IgnoreParens() : nullptr)) + dyn_cast_or_null(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_if_present(From->getTerminatorStmt())) { + dyn_cast_or_null(From->getTerminatorStmt())) { if (S->isAllEnumCasesCovered()) { const Stmt *L = To->getLabel(); if (!L || !isa(L)) diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 1dc35edded70b..087994e6ebd70 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_if_present(D)) { + if (const auto *VD = dyn_cast_or_null(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_if_present(BrE)) + if (const auto *BLE = dyn_cast_or_null(BrE)) branch = BLE->getValue(); - else if (const auto *ILE = dyn_cast_if_present(BrE)) + else if (const auto *ILE = dyn_cast_or_null(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_if_present(Exp->getCalleeDecl()); + auto *FunDecl = dyn_cast_or_null(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(); if (TagT && Exp->isPRValue()) { - auto [ThisPtr, DiagType] = + std::pair Placeholder = Analyzer->SxBuilder.createThisPlaceholder(Exp); [[maybe_unused]] auto inserted = - ConstructedObjects.insert({Exp, ThisPtr}); + ConstructedObjects.insert({Exp, Placeholder.first}); assert(inserted.second && "Are we visiting the same expression again?"); if (isa(Exp)) - Self = ThisPtr; + Self = Placeholder.first; if (TagT->getDecl()->hasAttr()) - Scp = CapabilityExpr(ThisPtr, DiagType, false); + Scp = CapabilityExpr(Placeholder.first, Placeholder.second, 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_if_present(D)) { + if (auto *VD = dyn_cast_or_null(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 S = Last.getAs(); - isa(S->getStmt())) - return true; - + if (std::optional S = Last.getAs()) { + if (isa(S->getStmt())) + return true; + } return false; }