Author: Kazu Hirata Date: 2024-12-03T13:53:20-08:00 New Revision: a9bf16d961e9bb0923b401bc26697c6ca707a1f5
URL: https://github.com/llvm/llvm-project/commit/a9bf16d961e9bb0923b401bc26697c6ca707a1f5 DIFF: https://github.com/llvm/llvm-project/commit/a9bf16d961e9bb0923b401bc26697c6ca707a1f5.diff LOG: [StaticAnalyzer] Migrate away from PointerUnion::{is,get} (NFC) (#118421) Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null. Added: Modified: clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp clang/lib/StaticAnalyzer/Core/MemRegion.cpp clang/lib/StaticAnalyzer/Core/SVals.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp index 9e81a6bd19fc5b..df23735e4668ee 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp @@ -211,9 +211,9 @@ class MallocSizeofChecker : public Checker<check::ASTCodeBody> { continue; const TypeSourceInfo *TSI = nullptr; - if (CallRec.CastedExprParent.is<const VarDecl *>()) { - TSI = CallRec.CastedExprParent.get<const VarDecl *>() - ->getTypeSourceInfo(); + if (const auto *VD = + dyn_cast<const VarDecl *>(CallRec.CastedExprParent)) { + TSI = VD->getTypeSourceInfo(); } else { TSI = CallRec.ExplicitCastType; } diff --git a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp index b0563b6c070f1f..827c04143e6588 100644 --- a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp +++ b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp @@ -196,13 +196,13 @@ const PointerToMemberData *BasicValueFactory::accumCXXBase( const NamedDecl *ND = nullptr; llvm::ImmutableList<const CXXBaseSpecifier *> BaseSpecList; - if (PTMDT.isNull() || PTMDT.is<const NamedDecl *>()) { - if (PTMDT.is<const NamedDecl *>()) - ND = PTMDT.get<const NamedDecl *>(); + if (PTMDT.isNull() || isa<const NamedDecl *>(PTMDT)) { + if (const auto *NDP = dyn_cast_if_present<const NamedDecl *>(PTMDT)) + ND = NDP; BaseSpecList = CXXBaseListFactory.getEmptyList(); } else { - const PointerToMemberData *PTMD = PTMDT.get<const PointerToMemberData *>(); + const auto *PTMD = cast<const PointerToMemberData *>(PTMDT); ND = PTMD->getDeclaratorDecl(); BaseSpecList = PTMD->getCXXBaseList(); diff --git a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp index 1e0cc2eea9ed85..c4af02f21f4943 100644 --- a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp @@ -211,9 +211,9 @@ void ExplodedNode::NodeGroup::replaceNode(ExplodedNode *node) { assert(!getFlag()); GroupStorage &Storage = reinterpret_cast<GroupStorage&>(P); - assert(Storage.is<ExplodedNode *>()); + assert(isa<ExplodedNode *>(Storage)); Storage = node; - assert(Storage.is<ExplodedNode *>()); + assert(isa<ExplodedNode *>(Storage)); } void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) { @@ -222,7 +222,7 @@ void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) { GroupStorage &Storage = reinterpret_cast<GroupStorage&>(P); if (Storage.isNull()) { Storage = N; - assert(Storage.is<ExplodedNode *>()); + assert(isa<ExplodedNode *>(Storage)); return; } @@ -230,7 +230,7 @@ void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) { if (!V) { // Switch from single-node to multi-node representation. - ExplodedNode *Old = Storage.get<ExplodedNode *>(); + auto *Old = cast<ExplodedNode *>(Storage); BumpVectorContext &Ctx = G.getNodeAllocator(); V = new (G.getAllocator()) ExplodedNodeVector(Ctx, 4); @@ -238,7 +238,7 @@ void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) { Storage = V; assert(!getFlag()); - assert(Storage.is<ExplodedNodeVector *>()); + assert(isa<ExplodedNodeVector *>(Storage)); } V->push_back(N, G.getNodeAllocator()); diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index ad4e43630dd44e..bbf2303b9f6ef3 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -1068,10 +1068,10 @@ const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D, llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V = getStackOrCaptureRegionForDeclContext(LC, DC, D); - if (V.is<const VarRegion*>()) - return V.get<const VarRegion*>(); + if (const auto *VR = dyn_cast_if_present<const VarRegion *>(V)) + return VR; - const auto *STC = V.get<const StackFrameContext *>(); + const auto *STC = cast<const StackFrameContext *>(V); if (!STC) { // FIXME: Assign a more sensible memory space to static locals diff --git a/clang/lib/StaticAnalyzer/Core/SVals.cpp b/clang/lib/StaticAnalyzer/Core/SVals.cpp index 84e7e033404c03..d009552965eca8 100644 --- a/clang/lib/StaticAnalyzer/Core/SVals.cpp +++ b/clang/lib/StaticAnalyzer/Core/SVals.cpp @@ -205,10 +205,10 @@ const NamedDecl *nonloc::PointerToMember::getDecl() const { return nullptr; const NamedDecl *ND = nullptr; - if (PTMD.is<const NamedDecl *>()) - ND = PTMD.get<const NamedDecl *>(); + if (const auto *NDP = dyn_cast<const NamedDecl *>(PTMD)) + ND = NDP; else - ND = PTMD.get<const PointerToMemberData *>()->getDeclaratorDecl(); + ND = cast<const PointerToMemberData *>(PTMD)->getDeclaratorDecl(); return ND; } @@ -227,16 +227,16 @@ nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const { nonloc::PointerToMember::iterator nonloc::PointerToMember::begin() const { const PTMDataType PTMD = getPTMData(); - if (PTMD.is<const NamedDecl *>()) + if (isa<const NamedDecl *>(PTMD)) return {}; - return PTMD.get<const PointerToMemberData *>()->begin(); + return cast<const PointerToMemberData *>(PTMD)->begin(); } nonloc::PointerToMember::iterator nonloc::PointerToMember::end() const { const PTMDataType PTMD = getPTMData(); - if (PTMD.is<const NamedDecl *>()) + if (isa<const NamedDecl *>(PTMD)) return {}; - return PTMD.get<const PointerToMemberData *>()->end(); + return cast<const PointerToMemberData *>(PTMD)->end(); } //===----------------------------------------------------------------------===// _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits