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

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


Author: kremenek
Date: Sat Aug 16 22:20:02 2008
New Revision: 54862

URL: http://llvm.org/viewvc/llvm-project?rev=54862&view=rev
Log:
Migrate the retain/release checker to not manage the RefBindings::Factory object
directly, but instead have GRStateManager manage it.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRStateTrait.h
    cfe/trunk/lib/Analysis/CFRefCount.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=54862&r1=54861&r2=54862&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Sat Aug 16 22:20:02 2008
@@ -566,6 +566,11 @@
     return GRStateRef(Mgr->remove<T>(St, K, C), *Mgr);
   }
   
+  template<typename T>
+  GRStateRef remove(typename GRStateTrait<T>::key_type K) {
+    return GRStateRef(Mgr->remove<T>(St, K, get_context<T>()), *Mgr);
+  }
+  
   // Pretty-printing.
   void print(std::ostream& Out, const char* nl = "\n",
              const char *sep = "") const;

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRStateTrait.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRStateTrait.h Sat Aug 16 22:20:02 2008
@@ -54,11 +54,11 @@
       return *((typename data_type::Factory*) p);
     }
     
-    static inline void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
+    static void* CreateContext(llvm::BumpPtrAllocator& Alloc) {
       return new typename data_type::Factory(Alloc);      
     }
     
-    static inline void DeleteContext(void* Ctx) {
+    static void DeleteContext(void* Ctx) {
       delete (typename data_type::Factory*) Ctx;
     }      
   };

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Sat Aug 16 22:20:02 2008
@@ -16,6 +16,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Analysis/PathSensitive/GRState.h"
+#include "clang/Analysis/PathSensitive/GRStateTrait.h"
 #include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Analysis/LocalCheckers.h"
 #include "clang/Analysis/PathDiagnostic.h"
@@ -1199,40 +1200,14 @@
 //===----------------------------------------------------------------------===//
   
 typedef llvm::ImmutableMap<SymbolID, RefVal> RefBindings;
-typedef RefBindings::Factory RefBFactoryTy;
-  
 static int RefBIndex = 0;
 
 namespace clang {
-template<> struct GRStateTrait<RefBindings> {
-  typedef RefBindings             data_type;
-  typedef RefBFactoryTy&          context_type;  
-  typedef SymbolID                key_type;
-  typedef RefVal                  value_type;
-  typedef const RefVal*           lookup_type;
-  
-  static RefBindings MakeData(void* const* p) {
-    return p ? RefBindings((RefBindings::TreeTy*) *p) : RefBindings(0);
-  }  
-  static void* MakeVoidPtr(RefBindings B) {
-    return B.getRoot();
-  }  
-  static void* GDMIndex() {
-    return &RefBIndex;
-  }  
-  static lookup_type Lookup(RefBindings B, SymbolID K) {
-    return B.lookup(K);
-  }  
-  static data_type Set(RefBindings B, key_type K, value_type E,
-                       RefBFactoryTy& F) {
-    return F.Add(B, K, E);
-  }
-  
-  static data_type Remove(RefBindings B, SymbolID K, RefBFactoryTy& F) {
-    return F.Remove(B, K);
-  }
-};
-}  
+  template<>
+  struct GRStateTrait<RefBindings> : public GRStatePartialTrait<RefBindings> {
+    static inline void* GDMIndex() { return &RefBIndex; }  
+  };
+}
   
 //===----------------------------------------------------------------------===//
 // Transfer functions.
@@ -1260,19 +1235,20 @@
 private:
   RetainSummaryManager Summaries;  
   const LangOptions&   LOpts;
-  RefBFactoryTy        RefBFactory;     
+
   UseAfterReleasesTy   UseAfterReleases;
   ReleasesNotOwnedTy   ReleasesNotOwned;
   LeaksTy              Leaks;
   
   RefBindings Update(RefBindings B, SymbolID sym, RefVal V, ArgEffect E,
-                     RefVal::Kind& hasErr);
+                     RefVal::Kind& hasErr, RefBindings::Factory& RefBFactory);
   
   RefVal::Kind& Update(GRStateRef& state, SymbolID sym, RefVal V,
                        ArgEffect E, RefVal::Kind& hasErr) {
     
     state = state.set<RefBindings>(Update(state.get<RefBindings>(), sym, V, 
-                                          E, hasErr));
+                                          E, hasErr,
+                                          state.get_context<RefBindings>()));
     return hasErr;
   }
   
@@ -1534,7 +1510,7 @@
         
         if (isa<lval::SymbolVal>(X)) {
           SymbolID Sym = cast<lval::SymbolVal>(X).getSymbol();
-          state = state.remove<RefBindings>(Sym, RefBFactory);
+          state = state.remove<RefBindings>(Sym);
         }
 
         // Set the value of the variable to be a conjured symbol.
@@ -1624,7 +1600,7 @@
       SymbolID Sym = Eng.getSymbolManager().getConjuredSymbol(Ex, Count);
       QualType RetT = GetReturnType(Ex, Eng.getContext());
       
-      state = state.set<RefBindings>(Sym, RefVal::makeOwned(RetT), RefBFactory);
+      state = state.set<RefBindings>(Sym, RefVal::makeOwned(RetT));
       state = state.SetRVal(Ex, lval::SymbolVal(Sym), false);
 
 #if 0
@@ -1644,7 +1620,7 @@
       SymbolID Sym = Eng.getSymbolManager().getConjuredSymbol(Ex, Count);
       QualType RetT = GetReturnType(Ex, Eng.getContext());
       
-      state = state.set<RefBindings>(Sym, RefVal::makeNotOwned(RetT), RefBFactory);
+      state = state.set<RefBindings>(Sym, RefVal::makeNotOwned(RetT));
       state = state.SetRVal(Ex, lval::SymbolVal(Sym), false);
       break;
     }
@@ -1747,7 +1723,7 @@
     return;
   
   // Nuke the binding.
-  state = state.remove<RefBindings>(Sym, RefBFactory);
+  state = state.remove<RefBindings>(Sym);
 
   // Hand of the remaining logic to the parent implementation.
   GRSimpleVals::EvalStore(Dst, Eng, Builder, E, Pred, state, TargetLV, Val);
@@ -1765,9 +1741,9 @@
   GRStateRef state(St, VMgr);
 
   if (!hasLeak)
-    return state.remove<RefBindings>(sid, RefBFactory);
+    return state.remove<RefBindings>(sid);
   
-  return state.set<RefBindings>(sid, V ^ RefVal::ErrorLeak, RefBFactory);
+  return state.set<RefBindings>(sid, V ^ RefVal::ErrorLeak);
 }
 
 void CFRefCount::EvalEndPath(GRExprEngine& Eng,
@@ -1899,7 +1875,7 @@
   }
   
   // Update the binding.
-  state = state.set<RefBindings>(Sym, X, RefBFactory);
+  state = state.set<RefBindings>(Sym, X);
   Builder.MakeNode(Dst, S, Pred, state);
 }
 
@@ -1922,6 +1898,9 @@
     return St;
   
   bool changed = false;
+  
+  GRStateRef state(St, VMgr);
+  RefBindings::Factory& RefBFactory = state.get_context<RefBindings>();
 
   for (RefBindings::iterator I=B.begin(), E=B.end(); I!=E; ++I) {    
     // Check if the symbol is null (or equal to any constant).
@@ -1932,17 +1911,16 @@
     }
   }
   
-  if (!changed)
-    return St;
+  if (changed)
+    state = state.set<RefBindings>(B);
   
-  GRStateRef state(St, VMgr);
-  state = state.set<RefBindings>(B);
   return state;
 }
 
 RefBindings CFRefCount::Update(RefBindings B, SymbolID sym,
                                RefVal V, ArgEffect E,
-                               RefVal::Kind& hasErr) {
+                               RefVal::Kind& hasErr,
+                               RefBindings::Factory& RefBFactory) {
   
   // FIXME: This dispatch can potentially be sped up by unifiying it into
   //  a single switch statement.  Opt for simplicity for now.





More information about the cfe-commits mailing list