Skip to content

[StaticAnalyzer] Migrate away from PointerUnion::{is,get} (NFC) #118421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -222,23 +222,23 @@ 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;
}

ExplodedNodeVector *V = Storage.dyn_cast<ExplodedNodeVector *>();

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);
V->push_back(Old, Ctx);

Storage = V;
assert(!getFlag());
assert(Storage.is<ExplodedNodeVector *>());
assert(isa<ExplodedNodeVector *>(Storage));
}

V->push_back(N, G.getNodeAllocator());
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/StaticAnalyzer/Core/MemRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions clang/lib/StaticAnalyzer/Core/SVals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
}

//===----------------------------------------------------------------------===//
Expand Down
Loading