[clang] [StaticAnalyzer] Migrate away from PointerUnion::dyn_cast (NFC) (PR #122856)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 13 21:06:29 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/122856
Note that PointerUnion::dyn_cast has 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>
Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Storage to be nonnull.
>From 492cea234d3d7b2a017d1e926272e95bf5fbfefc Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 13 Jan 2025 12:16:18 -0800
Subject: [PATCH] [StaticAnalyzer] Migrate away from PointerUnion::dyn_cast
(NFC)
Note that PointerUnion::dyn_cast has 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>
Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Storage to be nonnull.
---
clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
index c4af02f21f4943..2e3cdfe6cca748 100644
--- a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -226,7 +226,7 @@ void ExplodedNode::NodeGroup::addNode(ExplodedNode *N, ExplodedGraph &G) {
return;
}
- ExplodedNodeVector *V = Storage.dyn_cast<ExplodedNodeVector *>();
+ ExplodedNodeVector *V = dyn_cast_if_present<ExplodedNodeVector *>(Storage);
if (!V) {
// Switch from single-node to multi-node representation.
@@ -251,7 +251,8 @@ unsigned ExplodedNode::NodeGroup::size() const {
const GroupStorage &Storage = reinterpret_cast<const GroupStorage &>(P);
if (Storage.isNull())
return 0;
- if (ExplodedNodeVector *V = Storage.dyn_cast<ExplodedNodeVector *>())
+ if (ExplodedNodeVector *V =
+ dyn_cast_if_present<ExplodedNodeVector *>(Storage))
return V->size();
return 1;
}
@@ -263,7 +264,8 @@ ExplodedNode * const *ExplodedNode::NodeGroup::begin() const {
const GroupStorage &Storage = reinterpret_cast<const GroupStorage &>(P);
if (Storage.isNull())
return nullptr;
- if (ExplodedNodeVector *V = Storage.dyn_cast<ExplodedNodeVector *>())
+ if (ExplodedNodeVector *V =
+ dyn_cast_if_present<ExplodedNodeVector *>(Storage))
return V->begin();
return Storage.getAddrOfPtr1();
}
@@ -275,7 +277,8 @@ ExplodedNode * const *ExplodedNode::NodeGroup::end() const {
const GroupStorage &Storage = reinterpret_cast<const GroupStorage &>(P);
if (Storage.isNull())
return nullptr;
- if (ExplodedNodeVector *V = Storage.dyn_cast<ExplodedNodeVector *>())
+ if (ExplodedNodeVector *V =
+ dyn_cast_if_present<ExplodedNodeVector *>(Storage))
return V->end();
return Storage.getAddrOfPtr1() + 1;
}
More information about the cfe-commits
mailing list