llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Gábor Horváth (Xazax-hun)

<details>
<summary>Changes</summary>

Every ProgramState retain and release was an out-of-line call, and creating a 
state copied it twice: callers build a temporary copy, and getPersistentState 
copied that again into the uniqued slot before the temporary was destroyed. 
Each copy also retains the store through a virtual call, and RegionStore's 
retain/release built a temporary RegionBindingsRef, adding two more refcount 
operations.

- Inline the ProgramState retain and the release fast path. The 
IntrusiveRefCntPtrInfo members are templates so they are instantiated only 
where ProgramState is complete; freeing stays out of line.
- Give ProgramState a move constructor and move the temporary into the 
persistent slot.
- Give StoreRef move operations and use them when consuming a StoreRef.
- Retain/release the RegionStore tree root directly.
- Pass ProgramStateRef by const reference along the node creation path 
(CheckerContext::addTransition and friends, CoreEngine::makeNode, 
ExplodedGraph::getNode).

On some LLVM TUs (GVN, LiveVariables, RegionStore, SemaExpr) this reduces the 
instructions of the static analyzer by 2.1-3.0% and the cycles by 1.8-2.9%; 
peak memory is unchanged. The analyzer statistics and diagnostics are unchanged.

Assisted-by: Claude Opus 5.5

---

Patch is 20.90 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/244848.diff


12 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h (+8-11) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
(+2-2) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (+2-3) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (+17-5) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h (+4-8) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h 
(+11) 
- (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h 
(+2) 
- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Core/CoreEngine.cpp (+2-2) 
- (modified) clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp (+4-5) 
- (modified) clang/lib/StaticAnalyzer/Core/ProgramState.cpp (+24-31) 
- (modified) clang/lib/StaticAnalyzer/Core/RegionStore.cpp (+11-2) 


``````````diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
index 3ea2ad1310defe..05e8a142422ecf 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
@@ -191,7 +191,7 @@ class CheckerContext {
   ///        When \p Tag is nullptr, node creation will default to using the
   ///        active checker as the tag -- but if there is no state change,
   ///        the predecessor node may be returned even if it isn't tagged so.
-  ExplodedNode *addTransition(ProgramStateRef State = nullptr,
+  ExplodedNode *addTransition(const ProgramStateRef &State = nullptr,
                               const ProgramPointTag *Tag = nullptr) {
     if ((!State || State == getState()) && !Tag)
       return getPredecessor();
@@ -214,7 +214,7 @@ class CheckerContext {
   ///        used as a workaround when the node wouldn't be unique otherwise.
   ///        When \p Tag is nullptr, node creation will default to using the
   ///        active checker as the tag.
-  ExplodedNode *addTransition(ProgramStateRef State, ExplodedNode *Pred,
+  ExplodedNode *addTransition(const ProgramStateRef &State, ExplodedNode *Pred,
                               const ProgramPointTag *Tag = nullptr) {
     if (!Pred)
       Pred = getPredecessor();
@@ -241,7 +241,7 @@ class CheckerContext {
   /// @param Tag A ProgramPointTag that will be attached to the node; nullptr
   ///        (the default) means using the active checker as the tag. Using
   ///        another tag has no compelling use case (apart from debugging).
-  ExplodedNode *addSink(ProgramStateRef State = nullptr,
+  ExplodedNode *addSink(const ProgramStateRef &State = nullptr,
                         ExplodedNode *Pred = nullptr,
                         const ProgramPointTag *Tag = nullptr) {
     return addTransitionImpl(State, true, Pred, Tag);
@@ -263,7 +263,7 @@ class CheckerContext {
   ///        When \p Tag is nullptr, node creation will default to using the
   ///        active checker as the tag.
   ExplodedNode *
-  generateNonFatalErrorNode(ProgramStateRef State = nullptr,
+  generateNonFatalErrorNode(const ProgramStateRef &State = nullptr,
                             const ProgramPointTag *Tag = nullptr) {
     return addTransitionImpl(State, false, nullptr, Tag);
   }
@@ -284,8 +284,7 @@ class CheckerContext {
   ///        When \p Tag is nullptr, node creation will default to using the
   ///        active checker as the tag.
   ExplodedNode *
-  generateNonFatalErrorNode(ProgramStateRef State,
-                            ExplodedNode *Pred,
+  generateNonFatalErrorNode(const ProgramStateRef &State, ExplodedNode *Pred,
                             const ProgramPointTag *Tag = nullptr) {
     return addTransitionImpl(State, false, Pred, Tag);
   }
@@ -436,19 +435,17 @@ class CheckerContext {
   std::string getMacroNameOrSpelling(SourceLocation &Loc);
 
 private:
-  ExplodedNode *addTransitionImpl(ProgramStateRef State, bool MarkAsSink,
+  ExplodedNode *addTransitionImpl(const ProgramStateRef &State, bool 
MarkAsSink,
                                   ExplodedNode *P, const ProgramPointTag *Tag) 
{
     Changed = true;
     const ProgramPoint &LocalLoc = (Tag ? Location.withTag(Tag) : Location);
 
     if (!P)
       P = getPredecessor();
-    if (!State)
-      State = P->getState();
 
     Frontier.erase(P);
-    ExplodedNode *N =
-        Eng.getCoreEngine().makeNode(LocalLoc, State, P, MarkAsSink);
+    ExplodedNode *N = Eng.getCoreEngine().makeNode(
+        LocalLoc, State ? State : P->getState(), P, MarkAsSink);
 
     Frontier.insert(N);
     return N;
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
index 04906ef6c7189d..d180266856c553 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
@@ -171,10 +171,10 @@ class CoreEngine {
 
   auto aborted_blocks() const { return llvm::iterator_range(blocksAborted); }
 
-  ExplodedNode *makeNode(const ProgramPoint &Loc, ProgramStateRef State,
+  ExplodedNode *makeNode(const ProgramPoint &Loc, const ProgramStateRef &State,
                          ExplodedNode *Pred, bool MarkAsSink = false) const;
 
-  ExplodedNode *makePostStmtNode(const Stmt *S, ProgramStateRef State,
+  ExplodedNode *makePostStmtNode(const Stmt *S, const ProgramStateRef &State,
                                  ExplodedNode *Pred,
                                  bool MarkAsSink = false) const {
     PostStmt Loc(S, Pred->getStackFrame(), /*tag=*/nullptr);
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
index 1a8cf6fc376676..331a8d67e84239 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
@@ -346,9 +346,8 @@ class ExplodedGraph {
   /// Retrieve the node associated with a (Location, State) pair, where the
   /// 'Location' is a ProgramPoint in the CFG. If no node for this pair exists,
   /// it is created. IsNew is set to true if the node was freshly created.
-  ExplodedNode *getNode(const ProgramPoint &L, ProgramStateRef State,
-                        bool IsSink = false,
-                        bool* IsNew = nullptr);
+  ExplodedNode *getNode(const ProgramPoint &L, const ProgramStateRef &State,
+                        bool IsSink = false, bool *IsNew = nullptr);
 
   /// Create a node for a (Location, State) pair, but don't store it for
   /// deduplication later. This is useful when copying some nodes from an
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
index 3458fa9fe27a47..e789a49f4cd50e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -125,7 +125,7 @@ class ProgramState : public llvm::FoldingSetNode {
   }
   ProgramStateRef cloneAsPosteriorlyOverconstrained() const;
 
-  unsigned refCount;
+  mutable unsigned refCount;
 
   /// makeWithStore - Return a ProgramState with the same values as the current
   ///  state with the exception of using the specified Store.
@@ -142,6 +142,7 @@ class ProgramState : public llvm::FoldingSetNode {
   /// Copy ctor - We must explicitly define this or else the "Next" ptr
   ///  in FoldingSetNode will also get copied.
   ProgramState(const ProgramState &RHS);
+  ProgramState(ProgramState &&RHS);
 
   ~ProgramState();
 
@@ -483,8 +484,10 @@ class ProgramState : public llvm::FoldingSetNode {
   void dump() const;
 
 private:
-  friend void ProgramStateRetain(const ProgramState *state);
-  friend void ProgramStateRelease(const ProgramState *state);
+  friend struct llvm::IntrusiveRefCntPtrInfo<const ProgramState>;
+
+  void retain() const { ++refCount; }
+  void release() const;
 
   SVal desugarReference(SVal Val) const;
   SVal wrapSymbolicRegion(SVal Base) const;
@@ -496,7 +499,7 @@ class ProgramState : public llvm::FoldingSetNode {
 
 class ProgramStateManager {
   friend class ProgramState;
-  friend void ProgramStateRelease(const ProgramState *state);
+
 private:
   /// Eng - The ExprEngine that owns this state manager.
   ExprEngine *Eng; /* Can be null. */
@@ -527,6 +530,9 @@ class ProgramStateManager {
   /// A vector of ProgramStates that we can reuse.
   std::vector<ProgramState *> freeStates;
 
+  /// Called when the reference count of \p State drops to zero.
+  void freeState(ProgramState *State);
+
 public:
   ProgramStateManager(ASTContext &Ctx,
                  StoreManagerCreator CreateStoreManager,
@@ -598,7 +604,7 @@ class ProgramStateManager {
     StoreMgr->iterBindings(state->getStore(), F);
   }
 
-  ProgramStateRef getPersistentState(ProgramState &Impl);
+  ProgramStateRef getPersistentState(ProgramState &&Impl);
   ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState,
                                            ProgramStateRef GDMState);
 
@@ -690,6 +696,12 @@ class ProgramStateManager {
 // Out-of-line method definitions for ProgramState.
 
//===----------------------------------------------------------------------===//
 
+inline void ProgramState::release() const {
+  assert(refCount > 0);
+  if (--refCount == 0)
+    stateMgr->freeState(const_cast<ProgramState *>(this));
+}
+
 inline ConstraintManager &ProgramState::getConstraintManager() const {
   return stateMgr->getConstraintManager();
 }
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h
index 0ea26bf2e509bc..abc899198954cc 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h
@@ -16,19 +16,15 @@ namespace clang {
 namespace ento {
   class ProgramState;
   class ProgramStateManager;
-  void ProgramStateRetain(const ProgramState *state);
-  void ProgramStateRelease(const ProgramState *state);
 }
 }
 
 namespace llvm {
   template <> struct IntrusiveRefCntPtrInfo<const clang::ento::ProgramState> {
-    static void retain(const clang::ento::ProgramState *state) {
-      clang::ento::ProgramStateRetain(state);
-    }
-    static void release(const clang::ento::ProgramState *state) {
-      clang::ento::ProgramStateRelease(state);
-    }
+    // These are templates so that their bodies are only instantiated where
+    // ProgramState is complete, which lets them be inlined.
+    template <typename T> static void retain(T *state) { state->retain(); }
+    template <typename T> static void release(T *state) { state->release(); }
   };
 }
 
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
index cda21138fe5e3c..2f9f950ef8871f 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
@@ -323,6 +323,17 @@ inline StoreRef &StoreRef::operator=(StoreRef const 
&newStore) {
   return *this;
 }
 
+inline StoreRef &StoreRef::operator=(StoreRef &&newStore) {
+  assert(&newStore.mgr == &mgr);
+  if (this != &newStore) {
+    if (store)
+      mgr.decrementReferenceCount(store);
+    store = newStore.store;
+    newStore.store = nullptr;
+  }
+  return *this;
+}
+
 // FIXME: Do we need to pass ProgramStateManager anymore?
 std::unique_ptr<StoreManager>
 CreateRegionStoreManager(ProgramStateManager &StMgr);
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h
index a2dd05cfdf4c9a..fcacafbed86de9 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/StoreRef.h
@@ -33,7 +33,9 @@ class StoreRef {
 public:
   StoreRef(Store store, StoreManager &smgr);
   StoreRef(const StoreRef &sr);
+  StoreRef(StoreRef &&sr) : store(sr.store), mgr(sr.mgr) { sr.store = nullptr; 
}
   StoreRef &operator=(StoreRef const &newStore);
+  StoreRef &operator=(StoreRef &&newStore);
   ~StoreRef();
 
   bool operator==(const StoreRef &x) const {
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index 62eda2aae0171c..ff9890a0d47cbd 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -636,7 +636,7 @@ class SymbolReaper {
 
   /// Set to the value of the symbolic store after
   /// StoreManager::removeDeadBindings has been called.
-  void setReapedStore(StoreRef st) { reapedStore = st; }
+  void setReapedStore(StoreRef st) { reapedStore = std::move(st); }
 
 private:
   bool isLazilyCopiedRegion(const MemRegion *region) const;
diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 04b700726fbc68..c0667640f59fa6 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -560,8 +560,8 @@ void CoreEngine::HandleVirtualBaseBranch(const CFGBlock *B,
 }
 
 ExplodedNode *CoreEngine::makeNode(const ProgramPoint &Loc,
-                                   ProgramStateRef State, ExplodedNode *Pred,
-                                   bool MarkAsSink) const {
+                                   const ProgramStateRef &State,
+                                   ExplodedNode *Pred, bool MarkAsSink) const {
   bool IsPO = State->isPosteriorlyOverconstrained();
 
   bool IsNew;
diff --git a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp 
b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
index a73593baaa184e..62e49663bdd077 100644
--- a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -108,8 +108,8 @@ bool ExplodedGraph::shouldCollect(const ExplodedNode *node) 
{
     return false;
 
   // Conditions 5, 6, and 7.
-  ProgramStateRef state = node->getState();
-  ProgramStateRef pred_state = pred->getState();
+  const ProgramStateRef &state = node->getState();
+  const ProgramStateRef &pred_state = pred->getState();
   if (state->store != pred_state->store || state->GDM != pred_state->GDM ||
       progPoint.getStackFrame() != pred->getStackFrame())
     return false;
@@ -388,9 +388,8 @@ const Stmt 
*ExplodedNode::getCurrentOrPreviousStmtForDiagnostics() const {
 }
 
 ExplodedNode *ExplodedGraph::getNode(const ProgramPoint &L,
-                                     ProgramStateRef State,
-                                     bool IsSink,
-                                     bool* IsNew) {
+                                     const ProgramStateRef &State, bool IsSink,
+                                     bool *IsNew) {
   // Profile 'State' to determine if we already have an existing node.
   llvm::FoldingSetNodeID profile;
   llvm::FoldingSetInsertToken InsertToken;
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp 
b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index 123f4f7958d725..2b2c5691c2f589 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -23,25 +23,11 @@
 using namespace clang;
 using namespace ento;
 
-namespace clang { namespace  ento {
-/// Increments the number of times this state is referenced.
-
-void ProgramStateRetain(const ProgramState *state) {
-  ++const_cast<ProgramState*>(state)->refCount;
-}
-
-/// Decrement the number of times this state is referenced.
-void ProgramStateRelease(const ProgramState *state) {
-  assert(state->refCount > 0);
-  ProgramState *s = const_cast<ProgramState*>(state);
-  if (--s->refCount == 0) {
-    ProgramStateManager &Mgr = s->getStateManager();
-    Mgr.StateSet.erase(s);
-    s->~ProgramState();
-    Mgr.freeStates.push_back(s);
-  }
+void ProgramStateManager::freeState(ProgramState *State) {
+  StateSet.erase(State);
+  State->~ProgramState();
+  freeStates.push_back(State);
 }
-}}
 
 ProgramState::ProgramState(ProgramStateManager *mgr, const Environment& env,
                  StoreRef st, GenericDataMap gdm)
@@ -59,6 +45,13 @@ ProgramState::ProgramState(const ProgramState &RHS)
   stateMgr->getStoreManager().incrementReferenceCount(store);
 }
 
+ProgramState::ProgramState(ProgramState &&RHS)
+    : stateMgr(RHS.stateMgr), Env(std::move(RHS.Env)), store(RHS.store),
+      GDM(std::move(RHS.GDM)),
+      PosteriorlyOverconstrained(RHS.PosteriorlyOverconstrained), refCount(0) {
+  RHS.store = nullptr;
+}
+
 ProgramState::~ProgramState() {
   if (store)
     stateMgr->getStoreManager().decrementReferenceCount(store);
@@ -104,9 +97,9 @@ ProgramStateRef 
ProgramStateManager::removeDeadBindingsFromEnvironmentAndStore(
   StoreRef newStore =
       StoreMgr->removeDeadBindings(NewState.getStore(), SF, SymReaper);
   NewState.setStore(newStore);
-  SymReaper.setReapedStore(newStore);
+  SymReaper.setReapedStore(std::move(newStore));
 
-  return getPersistentState(NewState);
+  return getPersistentState(std::move(NewState));
 }
 
 ProgramStateRef ProgramState::bindLoc(Loc LV, SVal V, const StackFrame *SF,
@@ -301,7 +294,7 @@ ProgramStateRef ProgramState::BindExpr(const Expr *E, const 
StackFrame *SF,
 
   ProgramState NewSt = *this;
   NewSt.Env = std::move(NewEnv);
-  return getStateManager().getPersistentState(NewSt);
+  return getStateManager().getPersistentState(std::move(NewSt));
 }
 
 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
@@ -388,7 +381,7 @@ ProgramStateRef ProgramStateManager::getInitialState(const 
StackFrame *InitSF) {
                      StoreMgr->getInitialStore(InitSF),
                      GDMFactory.getEmptyMap());
 
-  return getPersistentState(State);
+  return getPersistentState(std::move(State));
 }
 
 ProgramStateRef ProgramStateManager::getPersistentStateWithGDM(
@@ -396,10 +389,10 @@ ProgramStateRef 
ProgramStateManager::getPersistentStateWithGDM(
                                                      ProgramStateRef GDMState) 
{
   ProgramState NewState(*FromState);
   NewState.GDM = GDMState->GDM;
-  return getPersistentState(NewState);
+  return getPersistentState(std::move(NewState));
 }
 
-ProgramStateRef ProgramStateManager::getPersistentState(ProgramState &State) {
+ProgramStateRef ProgramStateManager::getPersistentState(ProgramState &&State) {
 
   llvm::FoldingSetNodeID ID;
   State.Profile(ID);
@@ -416,7 +409,7 @@ ProgramStateRef 
ProgramStateManager::getPersistentState(ProgramState &State) {
   else {
     newState = Alloc.Allocate<ProgramState>();
   }
-  new (newState) ProgramState(State);
+  new (newState) ProgramState(std::move(State));
   StateSet.insert(newState, InsertToken);
   return newState;
 }
@@ -424,7 +417,7 @@ ProgramStateRef 
ProgramStateManager::getPersistentState(ProgramState &State) {
 ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const {
   ProgramState NewSt(*this);
   NewSt.setStore(store);
-  return getStateManager().getPersistentState(NewSt);
+  return getStateManager().getPersistentState(std::move(NewSt));
 }
 
 ProgramStateRef ProgramState::makeWithStore(const BindResult &BindRes) const {
@@ -442,7 +435,7 @@ ProgramStateRef ProgramState::makeWithStore(const 
BindResult &BindRes) const {
 ProgramStateRef ProgramState::cloneAsPosteriorlyOverconstrained() const {
   ProgramState NewSt(*this);
   NewSt.PosteriorlyOverconstrained = true;
-  return getStateManager().getPersistentState(NewSt);
+  return getStateManager().getPersistentState(std::move(NewSt));
 }
 
 void ProgramState::setStore(const StoreRef &newStore) {
@@ -548,8 +541,8 @@ ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef 
St, const void *Key,
     return St;
 
   ProgramState NewSt = *St;
-  NewSt.GDM = M2;
-  return getPersistentState(NewSt);
+  NewSt.GDM = std::move(M2);
+  return getPersistentState(std::move(NewSt));
 }
 
 ProgramStateRef ProgramStateManager::removeGDM(ProgramStateRef state,
@@ -561,8 +554,8 @@ ProgramStateRef 
ProgramStateManager::removeGDM(ProgramStateRef state,
     return state;
 
   ProgramState NewState = *state;
-  NewState.GDM = NewM;
-  return getPersistentState(NewState);
+  NewState.GDM = std::move(NewM);
+  return getPersistentState(std::move(NewState));
 }
 
 bool ScanReachableSymbols::scan(nonloc::LazyCompoundVal val) {
diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 6994917470ce84..dc3934e3b5e91e 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -688,14 +688,16 @@ class RegionStoreManager : public StoreManager {
   StoreRef killBinding(Store ST, Loc L) override;
 
   void incrementReferenceCount(Store store) override {
-    getRegionBindings(store).manualRetain();
+    if (RegionBindings::TreeTy *T = getRegionBindingsTree(store))
+      T->retain();
   }
 
   /// If the StoreManager supports it, decrement the reference count of
   /// the specified Store object.  I...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/244848
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to