Skip to content

Commit a9bf16d

Browse files
[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.
1 parent d5956fb commit a9bf16d

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

clang/lib/StaticAnalyzer/Checkers/MallocSizeofChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ class MallocSizeofChecker : public Checker<check::ASTCodeBody> {
211211
continue;
212212

213213
const TypeSourceInfo *TSI = nullptr;
214-
if (CallRec.CastedExprParent.is<const VarDecl *>()) {
215-
TSI = CallRec.CastedExprParent.get<const VarDecl *>()
216-
->getTypeSourceInfo();
214+
if (const auto *VD =
215+
dyn_cast<const VarDecl *>(CallRec.CastedExprParent)) {
216+
TSI = VD->getTypeSourceInfo();
217217
} else {
218218
TSI = CallRec.ExplicitCastType;
219219
}

clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ const PointerToMemberData *BasicValueFactory::accumCXXBase(
196196
const NamedDecl *ND = nullptr;
197197
llvm::ImmutableList<const CXXBaseSpecifier *> BaseSpecList;
198198

199-
if (PTMDT.isNull() || PTMDT.is<const NamedDecl *>()) {
200-
if (PTMDT.is<const NamedDecl *>())
201-
ND = PTMDT.get<const NamedDecl *>();
199+
if (PTMDT.isNull() || isa<const NamedDecl *>(PTMDT)) {
200+
if (const auto *NDP = dyn_cast_if_present<const NamedDecl *>(PTMDT))
201+
ND = NDP;
202202

203203
BaseSpecList = CXXBaseListFactory.getEmptyList();
204204
} else {
205-
const PointerToMemberData *PTMD = PTMDT.get<const PointerToMemberData *>();
205+
const auto *PTMD = cast<const PointerToMemberData *>(PTMDT);
206206
ND = PTMD->getDeclaratorDecl();
207207

208208
BaseSpecList = PTMD->getCXXBaseList();

clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ void ExplodedNode::NodeGroup::replaceNode(ExplodedNode *node) {
211211
assert(!getFlag());
212212

213213
GroupStorage &Storage = reinterpret_cast<GroupStorage&>(P);
214-
assert(Storage.is<ExplodedNode *>());
214+
assert(isa<ExplodedNode *>(Storage));
215215
Storage = node;
216-
assert(Storage.is<ExplodedNode *>());
216+
assert(isa<ExplodedNode *>(Storage));
217217
}
218218

219219
void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) {
@@ -222,23 +222,23 @@ void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) {
222222
GroupStorage &Storage = reinterpret_cast<GroupStorage&>(P);
223223
if (Storage.isNull()) {
224224
Storage = N;
225-
assert(Storage.is<ExplodedNode *>());
225+
assert(isa<ExplodedNode *>(Storage));
226226
return;
227227
}
228228

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

231231
if (!V) {
232232
// Switch from single-node to multi-node representation.
233-
ExplodedNode *Old = Storage.get<ExplodedNode *>();
233+
auto *Old = cast<ExplodedNode *>(Storage);
234234

235235
BumpVectorContext &Ctx = G.getNodeAllocator();
236236
V = new (G.getAllocator()) ExplodedNodeVector(Ctx, 4);
237237
V->push_back(Old, Ctx);
238238

239239
Storage = V;
240240
assert(!getFlag());
241-
assert(Storage.is<ExplodedNodeVector *>());
241+
assert(isa<ExplodedNodeVector *>(Storage));
242242
}
243243

244244
V->push_back(N, G.getNodeAllocator());

clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,10 @@ const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D,
10681068
llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V =
10691069
getStackOrCaptureRegionForDeclContext(LC, DC, D);
10701070

1071-
if (V.is<const VarRegion*>())
1072-
return V.get<const VarRegion*>();
1071+
if (const auto *VR = dyn_cast_if_present<const VarRegion *>(V))
1072+
return VR;
10731073

1074-
const auto *STC = V.get<const StackFrameContext *>();
1074+
const auto *STC = cast<const StackFrameContext *>(V);
10751075

10761076
if (!STC) {
10771077
// FIXME: Assign a more sensible memory space to static locals

clang/lib/StaticAnalyzer/Core/SVals.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ const NamedDecl *nonloc::PointerToMember::getDecl() const {
205205
return nullptr;
206206

207207
const NamedDecl *ND = nullptr;
208-
if (PTMD.is<const NamedDecl *>())
209-
ND = PTMD.get<const NamedDecl *>();
208+
if (const auto *NDP = dyn_cast<const NamedDecl *>(PTMD))
209+
ND = NDP;
210210
else
211-
ND = PTMD.get<const PointerToMemberData *>()->getDeclaratorDecl();
211+
ND = cast<const PointerToMemberData *>(PTMD)->getDeclaratorDecl();
212212

213213
return ND;
214214
}
@@ -227,16 +227,16 @@ nonloc::CompoundVal::iterator nonloc::CompoundVal::end() const {
227227

228228
nonloc::PointerToMember::iterator nonloc::PointerToMember::begin() const {
229229
const PTMDataType PTMD = getPTMData();
230-
if (PTMD.is<const NamedDecl *>())
230+
if (isa<const NamedDecl *>(PTMD))
231231
return {};
232-
return PTMD.get<const PointerToMemberData *>()->begin();
232+
return cast<const PointerToMemberData *>(PTMD)->begin();
233233
}
234234

235235
nonloc::PointerToMember::iterator nonloc::PointerToMember::end() const {
236236
const PTMDataType PTMD = getPTMData();
237-
if (PTMD.is<const NamedDecl *>())
237+
if (isa<const NamedDecl *>(PTMD))
238238
return {};
239-
return PTMD.get<const PointerToMemberData *>()->end();
239+
return cast<const PointerToMemberData *>(PTMD)->end();
240240
}
241241

242242
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)