https://github.com/steffenlarsen created https://github.com/llvm/llvm-project/pull/183477
This commit makes the GDM key in ProgramState a constant pointer. This is done to better reflect the intention of the key as a unique identifier for the data stored in the GDM, and to prevent the use of the storage pointed to by the key as global state. >From 723b7fb4f687f54d6da11e964591302fbe43e9b3 Mon Sep 17 00:00:00 2001 From: Steffen Holst Larsen <[email protected]> Date: Wed, 25 Feb 2026 07:35:46 -0600 Subject: [PATCH] [Clang][NFCI] Make program state GDM key const pointer This commit makes the GDM key in ProgramState a constant pointer. This is done to better reflect the intention of the key as a unique identifier for the data stored in the GDM, and to prevent the use of the storage pointed to by the key as global state. Signed-off-by: Steffen Holst Larsen <[email protected]> --- .../Core/PathSensitive/ProgramState.h | 17 +++++++++-------- clang/lib/StaticAnalyzer/Core/ProgramState.cpp | 15 ++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h index e8a63e6967805..d3dd6ca124b7f 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -70,7 +70,7 @@ template <typename T> struct ProgramStateTrait { /// values will never change. class ProgramState : public llvm::FoldingSetNode { public: - typedef llvm::ImmutableMap<void*, void*> GenericDataMap; + typedef llvm::ImmutableMap<const void *, void *> GenericDataMap; private: void operator=(const ProgramState& R) = delete; @@ -423,7 +423,7 @@ class ProgramState : public llvm::FoldingSetNode { // Accessing the Generic Data Map (GDM). //==---------------------------------------------------------------------==// - void *const* FindGDM(void *K) const; + void *const *FindGDM(const void *K) const; template <typename T> [[nodiscard]] ProgramStateRef @@ -512,7 +512,8 @@ class ProgramStateManager { ProgramState::GenericDataMap::Factory GDMFactory; - typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy; + typedef llvm::DenseMap<const void *, std::pair<void *, void (*)(void *)>> + GDMContextsTy; GDMContextsTy GDMContexts; /// StateSet - FoldingSet containing all the states created for analyzing @@ -595,8 +596,8 @@ class ProgramStateManager { } // Methods that manipulate the GDM. - ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data); - ProgramStateRef removeGDM(ProgramStateRef state, void *Key); + ProgramStateRef addGDM(ProgramStateRef St, const void *Key, void *Data); + ProgramStateRef removeGDM(ProgramStateRef state, const void *Key); // Methods that query & manipulate the Store. @@ -677,9 +678,9 @@ class ProgramStateManager { return removeGDM(st, ProgramStateTrait<T>::GDMIndex()); } - void *FindGDMContext(void *index, - void *(*CreateContext)(llvm::BumpPtrAllocator&), - void (*DeleteContext)(void*)); + void *FindGDMContext(const void *index, + void *(*CreateContext)(llvm::BumpPtrAllocator &), + void (*DeleteContext)(void *)); template <typename T> typename ProgramStateTrait<T>::context_type get_context() { diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp index 6932714bb6be7..87485daa6e5c9 100644 --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -531,14 +531,13 @@ AnalysisManager& ProgramState::getAnalysisManager() const { // Generic Data Map. //===----------------------------------------------------------------------===// -void *const* ProgramState::FindGDM(void *K) const { +void *const *ProgramState::FindGDM(const void *K) const { return GDM.lookup(K); } -void* -ProgramStateManager::FindGDMContext(void *K, - void *(*CreateContext)(llvm::BumpPtrAllocator&), - void (*DeleteContext)(void*)) { +void *ProgramStateManager::FindGDMContext( + const void *K, void *(*CreateContext)(llvm::BumpPtrAllocator &), + void (*DeleteContext)(void *)) { std::pair<void*, void (*)(void*)>& p = GDMContexts[K]; if (!p.first) { @@ -549,7 +548,8 @@ ProgramStateManager::FindGDMContext(void *K, return p.first; } -ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef St, void *Key, void *Data){ +ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef St, const void *Key, + void *Data) { ProgramState::GenericDataMap M1 = St->getGDM(); ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data); @@ -561,7 +561,8 @@ ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef St, void *Key, void return getPersistentState(NewSt); } -ProgramStateRef ProgramStateManager::removeGDM(ProgramStateRef state, void *Key) { +ProgramStateRef ProgramStateManager::removeGDM(ProgramStateRef state, + const void *Key) { ProgramState::GenericDataMap OldM = state->getGDM(); ProgramState::GenericDataMap NewM = GDMFactory.remove(OldM, Key); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
