[clang] [analyzer][NFC] Use a base region map in RemoveDeadBindingsWorker (PR #246433)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 26 12:12:54 PST 2026
================
@@ -3026,59 +3036,106 @@ RegionStoreManager::bindAggregate(LimitedRegionBindingsConstRef B,
//===----------------------------------------------------------------------===//
namespace {
-class RemoveDeadBindingsWorker
- : public ClusterAnalysis<RemoveDeadBindingsWorker> {
+class RemoveDeadBindingsWorker {
+ using ClusterInfo = DeadBindingsClusterInfo;
+
+ RegionStoreManager &RM;
+ RegionBindingsRef B;
SmallVector<const SymbolicRegion *, 12> Postponed;
SymbolReaper &SymReaper;
const StackFrame *CurrentSF;
-public:
- RemoveDeadBindingsWorker(RegionStoreManager &rm,
- ProgramStateManager &stateMgr, RegionBindingsRef b,
- SymbolReaper &symReaper, const StackFrame *SF)
- : ClusterAnalysis<RemoveDeadBindingsWorker>(rm, stateMgr, b),
- SymReaper(symReaper), CurrentSF(SF) {}
-
- // Called by ClusterAnalysis.
- void VisitAddedToCluster(const MemRegion *baseR, const ClusterBindings &C);
- void VisitCluster(const MemRegion *baseR, const ClusterBindings *C);
- using ClusterAnalysis<RemoveDeadBindingsWorker>::VisitCluster;
+ // Every cluster of the store by its base region, and whether it is live.
+ DeadBindingsClusterMapTy &Clusters;
+ SmallVector<std::pair<const MemRegion *, const ClusterBindings *>, 32>
+ ClusterWL;
+ unsigned NumVisited = 0;
- using ClusterAnalysis::AddToWorkList;
+ bool AddToWorkList(const MemRegion *BaseR, ClusterInfo &Info);
+ void VisitAddedToCluster(const MemRegion *baseR, ClusterInfo &Info);
+ void VisitCluster(const MemRegion *baseR, const ClusterBindings &C);
+ void VisitBinding(SVal V);
- bool AddToWorkList(const MemRegion *R);
+public:
+ RemoveDeadBindingsWorker(RegionStoreManager &rm, RegionBindingsRef b,
+ SymbolReaper &symReaper, const StackFrame *SF,
+ DeadBindingsClusterMapTy &Clusters)
+ : RM(rm), B(std::move(b)), SymReaper(symReaper), CurrentSF(SF),
+ Clusters(Clusters) {}
+ void GenerateClusters();
+ bool AddToWorkList(const MemRegion *R);
+ void RunWorkList();
bool UpdatePostponed();
- void VisitBinding(SVal V);
+
+ bool allVisited() const { return NumVisited == Clusters.size(); }
+ bool isVisited(const MemRegion *BaseR) const {
+ assert(BaseR == BaseR->getBaseRegion() && "Clusters are keyed by base");
----------------
NagyDonat wrote:
Be very careful with an analogous assertion when you're refactoring `InvalidateRegionsWorker`, the other subclass of `ClusterAnalysis` -- there we have a trait called `RegionAndSymbolInvalidationTraits::TK_DoNotInvalidateSuperRegion` which aims (or at least tries to aim) the invalidation at a part of a cluster. (I don't know whether that logic is actually functional, but I have an open internal ticket that would require fixing it.)
No action expected on this PR, I think (although I didn't deeply verify) that this algorithm always handles whole clusters.
https://github.com/llvm/llvm-project/pull/246433
More information about the cfe-commits
mailing list