From: Ted Kremenek Date: Sun, 17 Aug 2008 03:10:22 +0000 (+0000) Subject: Migrate GRState::ConstEqTy (map used from tracking constants for symbols) to use... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffdbefd4415c33c8e1a25a950f36cb8e1e2c8673;p=clang Migrate GRState::ConstEqTy (map used from tracking constants for symbols) to use the generic data map instead. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54860 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h index 8b2c72d849..9670f61e22 100644 --- a/include/clang/Analysis/PathSensitive/GRState.h +++ b/include/clang/Analysis/PathSensitive/GRState.h @@ -58,7 +58,6 @@ public: // Typedefs. typedef llvm::ImmutableSet IntSetTy; typedef llvm::ImmutableMap GenericDataMap; - typedef llvm::ImmutableMap ConstEqTy; typedef GRStateManager ManagerTy; @@ -73,16 +72,14 @@ private: // FIXME: Make these private. public: GenericDataMap GDM; - ConstEqTy ConstEq; public: /// This ctor is used when creating the first GRState object. - GRState(const Environment& env, Store st, GenericDataMap gdm, ConstEqTy CE) + GRState(const Environment& env, Store st, GenericDataMap gdm) : Env(env), St(st), - GDM(gdm), - ConstEq(CE) {} + GDM(gdm) {} /// Copy ctor - We must explicitly define this or else the "Next" ptr /// in FoldingSetNode will also get copied. @@ -90,8 +87,7 @@ public: : llvm::FoldingSetNode(), Env(RHS.Env), St(RHS.St), - GDM(RHS.GDM), - ConstEq(RHS.ConstEq) {} + GDM(RHS.GDM) {} /// getEnvironment - Return the environment associated with this state. /// The environment is the mapping from expressions to values. @@ -110,7 +106,6 @@ public: V->Env.Profile(ID); ID.AddPointer(V->St); V->GDM.Profile(ID); - V->ConstEq.Profile(ID); } /// Profile - Used to profile the contents of this object for inclusion @@ -243,10 +238,7 @@ private: typedef llvm::DenseMap > GDMContextsTy; GDMContextsTy GDMContexts; - - // FIXME: Refactor these elsewhere. - GRState::ConstEqTy::Factory CEFactory; - + /// Printers - A set of printer objects used for pretty-printing a GRState. /// GRStateManager owns these objects. std::vector Printers; @@ -297,7 +289,6 @@ public: StMgr(stmgr), ISetFactory(alloc), GDMFactory(alloc), - CEFactory(alloc), BasicVals(Ctx, alloc), SymMgr(alloc), Alloc(alloc), diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp index e5dd6788dc..f8725470c0 100644 --- a/lib/Analysis/GRState.cpp +++ b/lib/Analysis/GRState.cpp @@ -34,7 +34,9 @@ GRStateManager::~GRStateManager() { //===----------------------------------------------------------------------===// typedef llvm::ImmutableMap ConstNotEqTy; +typedef llvm::ImmutableMap ConstEqTy; +static int ConstEqTyIndex = 0; static int ConstNotEqTyIndex = 0; namespace clang { @@ -42,6 +44,11 @@ namespace clang { struct GRStateTrait : public GRStatePartialTrait { static inline void* GDMIndex() { return &ConstNotEqTyIndex; } }; + + template<> + struct GRStateTrait : public GRStatePartialTrait { + static inline void* GDMIndex() { return &ConstEqTyIndex; } + }; } bool GRState::isNotEqual(SymbolID sym, const llvm::APSInt& V) const { @@ -54,16 +61,14 @@ bool GRState::isNotEqual(SymbolID sym, const llvm::APSInt& V) const { } bool GRState::isEqual(SymbolID sym, const llvm::APSInt& V) const { - // Retrieve the EQ-set associated with the given symbol. - const ConstEqTy::data_type* T = ConstEq.lookup(sym); - + const ConstEqTy::data_type* T = get(sym); // See if V is present in the EQ-set. return T ? **T == V : false; } const llvm::APSInt* GRState::getSymVal(SymbolID sym) const { - ConstEqTy::data_type* T = ConstEq.lookup(sym); + const ConstEqTy::data_type* T = get(sym); return T ? *T : NULL; } @@ -123,20 +128,23 @@ GRStateManager::RemoveDeadBindings(const GRState* St, Stmt* Loc, NewSt.St = StMgr->RemoveDeadBindings(St->getStore(), Loc, Liveness, DRoots, LSymbols, DSymbols); + + GRStateRef state(getPersistentState(NewSt), *this); + // Remove the dead symbols from the symbol tracker. // FIXME: Refactor into something else that manages symbol values. - for (GRState::ConstEqTy::iterator I = St->ConstEq.begin(), - E=St->ConstEq.end(); I!=E; ++I) { - SymbolID sym = I.getKey(); - + ConstEqTy CE = state.get(); + ConstEqTy::Factory& CEFactory = state.get_context(); + + for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) { + SymbolID sym = I.getKey(); if (!LSymbols.count(sym)) { DSymbols.insert(sym); - NewSt.ConstEq = CEFactory.Remove(NewSt.ConstEq, sym); + CE = CEFactory.Remove(CE, sym); } } - GRStateRef state(getPersistentState(NewSt), *this); ConstNotEqTy CNE = state.get(); ConstNotEqTy::Factory& CNEFactory = state.get_context(); @@ -196,20 +204,15 @@ const GRState* GRStateManager::AddNE(const GRState* St, SymbolID sym, const GRState* GRStateManager::AddEQ(const GRState* St, SymbolID sym, const llvm::APSInt& V) { - // Create a new state with the old binding replaced. - GRState NewSt = *St; - NewSt.ConstEq = CEFactory.Add(NewSt.ConstEq, sym, &V); - - // Get the persistent copy. - return getPersistentState(NewSt); + GRStateRef state(St, *this); + return state.set(sym, &V); } const GRState* GRStateManager::getInitialState() { GRState StateImpl(EnvMgr.getInitialEnvironment(), StMgr->getInitialStore(), - GDMFactory.GetEmptyMap(), - CEFactory.GetEmptyMap()); + GDMFactory.GetEmptyMap()); return getPersistentState(StateImpl); } @@ -289,17 +292,14 @@ void GRState::print(std::ostream& Out, Printer** Beg, Printer** End, // Print equality constraints. // FIXME: Make just another printer do this. - - if (!ConstEq.isEmpty()) { - + ConstEqTy CE = get(); + + if (!CE.isEmpty()) { Out << nl << sep << "'==' constraints:"; - - for (ConstEqTy::iterator I = ConstEq.begin(), - E = ConstEq.end(); I!=E; ++I) { - + + for (ConstEqTy::iterator I = CE.begin(), E = CE.end(); I!=E; ++I) Out << nl << " $" << I.getKey() << " : " << I.getData()->toString(); - } } // Print != constraints. @@ -308,7 +308,6 @@ void GRState::print(std::ostream& Out, Printer** Beg, Printer** End, ConstNotEqTy CNE = get(); if (!CNE.isEmpty()) { - Out << nl << sep << "'!=' constraints:"; for (ConstNotEqTy::iterator I = CNE.begin(), EI = CNE.end(); I!=EI; ++I) {