[cfe-commits] r54860 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRState.h lib/Analysis/GRState.cpp

Ted Kremenek kremenek at apple.com
Sat Aug 16 20:10:24 PDT 2008


Author: kremenek
Date: Sat Aug 16 22:10:22 2008
New Revision: 54860

URL: http://llvm.org/viewvc/llvm-project?rev=54860&view=rev
Log:
Migrate GRState::ConstEqTy (map used from tracking constants for symbols) to use the generic data map instead.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
    cfe/trunk/lib/Analysis/GRState.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h?rev=54860&r1=54859&r2=54860&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Sat Aug 16 22:10:22 2008
@@ -58,7 +58,6 @@
   // Typedefs.  
   typedef llvm::ImmutableSet<llvm::APSInt*>                IntSetTy;
   typedef llvm::ImmutableMap<void*, void*>                 GenericDataMap;  
-  typedef llvm::ImmutableMap<SymbolID,const llvm::APSInt*> ConstEqTy;
   
   typedef GRStateManager ManagerTy;
   
@@ -73,16 +72,14 @@
   // 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 @@
     : 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 @@
     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 @@
   
   typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > 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<GRState::Printer*> Printers;
@@ -297,7 +289,6 @@
     StMgr(stmgr),
     ISetFactory(alloc), 
     GDMFactory(alloc),
-    CEFactory(alloc),
     BasicVals(Ctx, alloc),
     SymMgr(alloc),
     Alloc(alloc),

Modified: cfe/trunk/lib/Analysis/GRState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRState.cpp?rev=54860&r1=54859&r2=54860&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Sat Aug 16 22:10:22 2008
@@ -34,7 +34,9 @@
 //===----------------------------------------------------------------------===//
 
 typedef llvm::ImmutableMap<SymbolID,GRState::IntSetTy> ConstNotEqTy;
+typedef llvm::ImmutableMap<SymbolID,const llvm::APSInt*> ConstEqTy;
 
+static int ConstEqTyIndex = 0;
 static int ConstNotEqTyIndex = 0;
 
 namespace clang {
@@ -42,6 +44,11 @@
   struct GRStateTrait<ConstNotEqTy> : public GRStatePartialTrait<ConstNotEqTy> {
     static inline void* GDMIndex() { return &ConstNotEqTyIndex; }  
   };
+  
+  template<>
+  struct GRStateTrait<ConstEqTy> : public GRStatePartialTrait<ConstEqTy> {
+    static inline void* GDMIndex() { return &ConstEqTyIndex; }  
+  };
 }
 
 bool GRState::isNotEqual(SymbolID sym, const llvm::APSInt& V) const {
@@ -54,16 +61,14 @@
 }
 
 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<ConstEqTy>(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<ConstEqTy>(sym);
   return T ? *T : NULL;  
 }
 
@@ -123,20 +128,23 @@
   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>();
+  ConstEqTy::Factory& CEFactory = state.get_context<ConstEqTy>();
+
+  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>();
   ConstNotEqTy::Factory& CNEFactory = state.get_context<ConstNotEqTy>();
 
@@ -196,20 +204,15 @@
 
 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<ConstEqTy>(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 @@
   
   // Print equality constraints.
   // FIXME: Make just another printer do this.
-  
-  if (!ConstEq.isEmpty()) {
-  
+  ConstEqTy CE = get<ConstEqTy>();
+
+  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 @@
   ConstNotEqTy CNE = get<ConstNotEqTy>();
   
   if (!CNE.isEmpty()) {
-  
     Out << nl << sep << "'!=' constraints:";
   
     for (ConstNotEqTy::iterator I = CNE.begin(), EI = CNE.end(); I!=EI; ++I) {





More information about the cfe-commits mailing list