[cfe-commits] r74812 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Store.h lib/Analysis/CFRefCount.cpp lib/Analysis/Store.cpp

Zhongxing Xu xuzhongxing at gmail.com
Sun Jul 5 20:41:35 PDT 2009


Author: zhongxingxu
Date: Sun Jul  5 22:41:27 2009
New Revision: 74812

URL: http://llvm.org/viewvc/llvm-project?rev=74812&view=rev
Log:
Start to gradually move region invalidation code into store manager.
No functionality change. 

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

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Store.h Sun Jul  5 22:41:27 2009
@@ -157,6 +157,8 @@
   virtual const GRState *BindDeclWithNoInit(const GRState *state,
                                              const VarDecl *vd) = 0;
 
+  const GRState *InvalidateRegion(const GRState *state, const TypedRegion *R,
+                                  const Expr *E, unsigned Count);
   // FIXME: Make out-of-line.
   virtual const GRState *setExtent(const GRState *state,
                                     const MemRegion *region, SVal extent) {

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Sun Jul  5 22:41:27 2009
@@ -2797,7 +2797,8 @@
         //  disambiguate conjured symbols. 
         unsigned Count = Builder.getCurrentBlockCount();
         const TypedRegion* R = dyn_cast<TypedRegion>(MR->getRegion());
-
+        StoreManager& StoreMgr = 
+          Eng.getStateManager().getStoreManager();
         if (R) {
           // Are we dealing with an ElementRegion?  If the element type is
           // a basic integer type (e.g., char, int) and the underying region
@@ -2829,78 +2830,14 @@
           
           // Remove any existing reference-count binding.
           if (Sym) state = state->remove<RefBindings>(Sym);
-          
-          if (R->isBoundable()) {
-            // Set the value of the variable to be a conjured symbol.
 
-            QualType T = R->getValueType(Ctx);
-          
-            if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())){
-              ValueManager &ValMgr = Eng.getValueManager();
-              SVal V = ValMgr.getConjuredSymbolVal(*I, T, Count);
-              state = state->bindLoc(ValMgr.makeLoc(R), V);
-            }
-            else if (const RecordType *RT = T->getAsStructureType()) {
-              // Handle structs in a not so awesome way.  Here we just
-              // eagerly bind new symbols to the fields.  In reality we
-              // should have the store manager handle this.  The idea is just
-              // to prototype some basic functionality here.  All of this logic
-              // should one day soon just go away.
-              const RecordDecl *RD = RT->getDecl()->getDefinition(Ctx);
-              
-              // No record definition.  There is nothing we can do.
-              if (!RD)
-                continue;
-              
-              MemRegionManager &MRMgr =
-                state->getStateManager().getRegionManager();
-              
-              // Iterate through the fields and construct new symbols.
-              for (RecordDecl::field_iterator FI=RD->field_begin(),
-                   FE=RD->field_end(); FI!=FE; ++FI) {
-                
-                // For now just handle scalar fields.
-                FieldDecl *FD = *FI;
-                QualType FT = FD->getType();
-                const FieldRegion* FR = MRMgr.getFieldRegion(FD, R);
-
-                if (Loc::IsLocType(FT) || 
-                    (FT->isIntegerType() && FT->isScalarType())) {
-                  SVal V = ValMgr.getConjuredSymbolVal(*I, FT, Count);
-                  state = state->bindLoc(ValMgr.makeLoc(FR), V);
-                }
-                else if (FT->isStructureType()) {
-                  // set the default value of the struct field to conjured
-                  // symbol. Note that the type of the symbol is irrelavant.
-                  // We cannot use the type of the struct otherwise ValMgr won't
-                  // give us the conjured symbol.
-                  StoreManager& StoreMgr = 
-                    Eng.getStateManager().getStoreManager();
-                  SVal V = ValMgr.getConjuredSymbolVal(*I, 
-                                                       Eng.getContext().IntTy,
-                                                       Count);
-                  state = StoreMgr.setDefaultValue(state, FR, V);
-                }
-              }
-            } else if (const ArrayType *AT = Ctx.getAsArrayType(T)) {
-              // Set the default value of the array to conjured symbol.
-              StoreManager& StoreMgr = Eng.getStateManager().getStoreManager();
-              SVal V = ValMgr.getConjuredSymbolVal(*I, AT->getElementType(),
-                                                   Count);
-              state = StoreMgr.setDefaultValue(state, R, V);
-            } else {
-              // Just blast away other values.
-              state = state->bindLoc(*MR, UnknownVal());
-            }
-          }
+          state = StoreMgr.InvalidateRegion(state, R, *I, Count);
         }
         else if (isa<AllocaRegion>(MR->getRegion())) {
           // Invalidate the alloca region by setting its default value to 
           // conjured symbol. The type of the symbol is irrelavant.
           SVal V = ValMgr.getConjuredSymbolVal(*I, Eng.getContext().IntTy, 
                                                Count);
-          StoreManager& StoreMgr = 
-                    Eng.getStateManager().getStoreManager();
           state = StoreMgr.setDefaultValue(state, MR->getRegion(), V);
         }
         else

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

==============================================================================
--- cfe/trunk/lib/Analysis/Store.cpp (original)
+++ cfe/trunk/lib/Analysis/Store.cpp Sun Jul  5 22:41:27 2009
@@ -109,3 +109,60 @@
   
   return CastResult(state, R);
 }
+
+const GRState *StoreManager::InvalidateRegion(const GRState *state,
+                                              const TypedRegion *R,
+                                              const Expr *E, unsigned Count) {
+  if (!R->isBoundable())
+    return state;
+
+  ASTContext& Ctx = StateMgr.getContext();
+  QualType T = R->getValueType(Ctx);
+
+  if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) {
+    SVal V = ValMgr.getConjuredSymbolVal(E, T, Count);
+    return Bind(state, ValMgr.makeLoc(R), V);
+  }
+  else if (const RecordType *RT = T->getAsStructureType()) {
+    // FIXME: handle structs with default region value.
+    const RecordDecl *RD = RT->getDecl()->getDefinition(Ctx);
+
+    // No record definition.  There is nothing we can do.
+    if (!RD)
+      return state;
+
+    // Iterate through the fields and construct new symbols.
+    for (RecordDecl::field_iterator FI=RD->field_begin(),
+           FE=RD->field_end(); FI!=FE; ++FI) {
+      
+      // For now just handle scalar fields.
+      FieldDecl *FD = *FI;
+      QualType FT = FD->getType();
+      const FieldRegion* FR = MRMgr.getFieldRegion(FD, R);
+      
+      if (Loc::IsLocType(FT) || 
+          (FT->isIntegerType() && FT->isScalarType())) {
+        SVal V = ValMgr.getConjuredSymbolVal(E, FT, Count);
+        state = state->bindLoc(ValMgr.makeLoc(FR), V);
+      }
+      else if (FT->isStructureType()) {
+        // set the default value of the struct field to conjured
+        // symbol. Note that the type of the symbol is irrelavant.
+        // We cannot use the type of the struct otherwise ValMgr won't
+        // give us the conjured symbol.
+        SVal V = ValMgr.getConjuredSymbolVal(E, Ctx.IntTy, Count);
+        state = setDefaultValue(state, FR, V);
+      }
+    }
+  } else if (const ArrayType *AT = Ctx.getAsArrayType(T)) {
+    // Set the default value of the array to conjured symbol.
+    SVal V = ValMgr.getConjuredSymbolVal(E, AT->getElementType(),
+                                         Count);
+    state = setDefaultValue(state, R, V);
+  } else {
+    // Just blast away other values.
+    state = Bind(state, ValMgr.makeLoc(R), UnknownVal());
+  }
+  
+  return state;
+}





More information about the cfe-commits mailing list