aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/RegionStore.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2008-11-02 12:13:30 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2008-11-02 12:13:30 +0000
commitd463d44c6a1c8d6682419aaa9b7eee6ebed62e09 (patch)
tree5908f890aa9dd0864173d27f3e400cb318bbc723 /lib/Analysis/RegionStore.cpp
parent3cab2b1c3798f2a6aa3526875801a02aebf6fc1d (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58564 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r--lib/Analysis/RegionStore.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 1755ee2662..04aa41e056 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -111,10 +111,10 @@ private:
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 @@ Store RegionStoreManager::BindStruct(Store store, const TypedRegion* R, SVal V){
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 @@ Store RegionStoreManager::BindDecl(Store store, const VarDecl* VD, Expr* Ex,
} 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 @@ void RegionStoreManager::print(Store store, std::ostream& Out,
}
}
-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 @@ Store RegionStoreManager::InitializeArray(Store store, TypedRegion* R,
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 @@ Store RegionStoreManager::InitializeArrayToUndefined(Store store,
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 RegionStoreManager::InitializeStruct(Store store, TypedRegion* R,
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 @@ Store RegionStoreManager::InitializeStructToUndefined(Store store,
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);
}
}