[cfe-commits] r58564 - /cfe/trunk/lib/Analysis/RegionStore.cpp

Zhongxing Xu xuzhongxing at gmail.com
Sun Nov 2 04:13:30 PST 2008


Author: zhongxingxu
Date: Sun Nov  2 06:13:30 2008
New Revision: 58564

URL: http://llvm.org/viewvc/llvm-project?rev=58564&view=rev
Log:
1. When a pointer to struct is used as an argument, GRSimpleVals::EvalCall()
   sets the whole struct to Unknown. Then we cannot assume the V passed to
   BindStruct() is always a CompoundVal. When it is an UnknownVal, we call
   BindStructToVal(UnknownVal).

2. Change the signature of InitializeStructToUndefined() to BindStructToVal()
   to reuse the code.

Modified:
    cfe/trunk/lib/Analysis/RegionStore.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Sun Nov  2 06:13:30 2008
@@ -111,10 +111,10 @@
     return loc::MemRegionVal(MRMgr.getVarRegion(VD));
   }
 
-  Store InitializeArray(Store store, TypedRegion* R, SVal Init);
-  Store InitializeArrayToUndefined(Store store, TypedRegion* BaseR);
-  Store InitializeStruct(Store store, TypedRegion* R, SVal Init);
-  Store InitializeStructToUndefined(Store store, TypedRegion* BaseR);
+  Store InitializeArray(Store store, const TypedRegion* R, SVal Init);
+  Store BindArrayToVal(Store store, const TypedRegion* BaseR, SVal V);
+  Store InitializeStruct(Store store, const TypedRegion* R, SVal Init);
+  Store BindStructToVal(Store store, const TypedRegion* BaseR, SVal V);
 
   SVal RetrieveStruct(Store store, const TypedRegion* R);
   Store BindStruct(Store store, const TypedRegion* R, SVal V);
@@ -309,6 +309,9 @@
 
   RegionBindingsTy B = GetRegionBindings(store);
 
+  if (isa<UnknownVal>(V))
+    return BindStructToVal(store, R, UnknownVal());
+
   nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V);
 
   nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
@@ -405,13 +408,13 @@
 
     } else if (T->isArrayType()) {
       if (!Ex)
-        store = InitializeArrayToUndefined(store, VR);
+        store = BindArrayToVal(store, VR, UndefinedVal());
       else
         store = InitializeArray(store, VR, InitVal);
 
     } else if (T->isStructureType()) {
       if (!Ex)
-        store = InitializeStructToUndefined(store, VR);
+        store = BindStructToVal(store, VR, UndefinedVal());
       else
         store = InitializeStruct(store, VR, InitVal);
     }
@@ -433,7 +436,7 @@
   }
 }
 
-Store RegionStoreManager::InitializeArray(Store store, TypedRegion* R, 
+Store RegionStoreManager::InitializeArray(Store store, const TypedRegion* R, 
                                           SVal Init) {
   QualType T = R->getType(getContext());
   assert(T->isArrayType());
@@ -461,8 +464,9 @@
   return store;
 }
 
-Store RegionStoreManager::InitializeArrayToUndefined(Store store, 
-                                                     TypedRegion* BaseR) {
+// Bind all elements of the array to some value.
+Store RegionStoreManager::BindArrayToVal(Store store, const TypedRegion* BaseR,
+                                         SVal V){
   QualType T = BaseR->getType(getContext());
   assert(T->isArrayType());
 
@@ -476,14 +480,14 @@
 
       ElementRegion* ER = MRMgr.getElementRegion(Idx, BaseR);
 
-      store = Bind(store, loc::MemRegionVal(ER), UndefinedVal());
+      store = Bind(store, loc::MemRegionVal(ER), V);
     }
   }
 
   return store;
 }
 
-Store RegionStoreManager::InitializeStruct(Store store, TypedRegion* R, 
+Store RegionStoreManager::InitializeStruct(Store store, const TypedRegion* R, 
                                            SVal Init) {
   QualType T = R->getType(getContext());
   assert(T->isStructureType());
@@ -512,21 +516,22 @@
         store = InitializeArray(store, FR, *VI);
         ++VI;
       } else
-        store = InitializeArrayToUndefined(store, FR);
+        store = BindArrayToVal(store, FR, UndefinedVal());
     }
     else if (FTy->isStructureType()) {
       if (VI != VE) {
         store = InitializeStruct(store, FR, *VI);
         ++VI;
       } else
-        store = InitializeStructToUndefined(store, FR);
+        store = BindStructToVal(store, FR, UndefinedVal());
     }
   }
   return store;
 }
 
-Store RegionStoreManager::InitializeStructToUndefined(Store store,
-                                                      TypedRegion* BaseR) {
+// Bind all fields of the struct to some value.
+Store RegionStoreManager::BindStructToVal(Store store, const TypedRegion* BaseR,
+                                          SVal V) {
   QualType T = BaseR->getType(getContext());
   assert(T->isStructureType());
 
@@ -542,13 +547,13 @@
     FieldRegion* FR = MRMgr.getFieldRegion(*I, BaseR);
     
     if (Loc::IsLocType(FTy) || FTy->isIntegerType()) {
-      store = Bind(store, loc::MemRegionVal(FR), UndefinedVal());
+      store = Bind(store, loc::MemRegionVal(FR), V);
 
     } else if (FTy->isArrayType()) {
-      store = InitializeArrayToUndefined(store, FR);
+      store = BindArrayToVal(store, FR, V);
 
     } else if (FTy->isStructureType()) {
-      store = InitializeStructToUndefined(store, FR);
+      store = BindStructToVal(store, FR, V);
     }
   }
 





More information about the cfe-commits mailing list