diff options
author | Timm Bäder <tbaeder@redhat.com> | 2023-06-21 11:15:55 +0200 |
---|---|---|
committer | Timm Bäder <tbaeder@redhat.com> | 2023-06-27 11:38:41 +0200 |
commit | 173df3dd5f9a812b07f9866965f4e92a982a3fca (patch) | |
tree | fa2b6f9bb68ee96723ea50c3c1654162b2a486b2 /clang/lib/Analysis/ThreadSafety.cpp | |
parent | c3196947312e530960fde1b8849a4a848a5095f3 (diff) | |
download | llvm-173df3dd5f9a812b07f9866965f4e92a982a3fca.zip llvm-173df3dd5f9a812b07f9866965f4e92a982a3fca.tar.gz llvm-173df3dd5f9a812b07f9866965f4e92a982a3fca.tar.bz2 |
[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.
Diffstat (limited to 'clang/lib/Analysis/ThreadSafety.cpp')
-rw-r--r-- | clang/lib/Analysis/ThreadSafety.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp index 087994e..1dc35ed 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; } |