From 0a6e09f67c719c318856be19d57e19972101f62c Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 6 Dec 2012 23:55:34 +0000 Subject: [PATCH] [analyzer] Avoid ProgramStateRef copy constructors. Suggested by David Blaikie. ExplodedNode, CallEvent, and CheckerContext all hang onto their ProgramState, so the accessors can return a reference to the internal state rather than preemptively copying it. This helps avoid temporary ProgramStateRefs, though local variables will still (correctly) do an extra retain and release. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169563 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h | 8 +++++--- .../StaticAnalyzer/Core/PathSensitive/CheckerContext.h | 2 +- .../StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h index bfb255a6d5..1570d95737 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h @@ -142,10 +142,12 @@ private: protected: friend class CallEventManager; - CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx) + CallEvent(const Expr *E, const ProgramStateRef &state, + const LocationContext *lctx) : State(state), LCtx(lctx), Origin(E), RefCount(0) {} - CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx) + CallEvent(const Decl *D, const ProgramStateRef &state, + const LocationContext *lctx) : State(state), LCtx(lctx), Origin(D), RefCount(0) {} // DO NOT MAKE PUBLIC @@ -181,7 +183,7 @@ public: } /// \brief The state in which the call is being evaluated. - ProgramStateRef getState() const { + const ProgramStateRef &getState() const { return State; } diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h index 4558cd9c94..42e50abbbe 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h @@ -119,7 +119,7 @@ public: /// the state of the program before the checker ran. Note, checkers should /// not retain the node in their state since the nodes might get invalidated. ExplodedNode *getPredecessor() { return Pred; } - ProgramStateRef getState() const { return Pred->getState(); } + const ProgramStateRef &getState() const { return Pred->getState(); } /// \brief Check if the checker changed the state of the execution; ex: added /// a new transition or a bug report. diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h index 971a280384..35b6564507 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h @@ -122,7 +122,7 @@ class ExplodedNode : public llvm::FoldingSetNode { public: - explicit ExplodedNode(const ProgramPoint &loc, ProgramStateRef state, + explicit ExplodedNode(const ProgramPoint &loc, const ProgramStateRef &state, bool IsSink) : Location(loc), State(state), Succs(IsSink) { assert(isSink() == IsSink); @@ -152,7 +152,7 @@ public: return *getLocationContext()->getAnalysis(); } - ProgramStateRef getState() const { return State; } + const ProgramStateRef &getState() const { return State; } template const T* getLocationAs() const LLVM_LVALUE_FUNCTION { -- 2.40.0