aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/RegionStore.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2008-10-31 07:16:08 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2008-10-31 07:16:08 +0000
commit6e3f01cef27dd6cc7e36769618820c5b984f61da (patch)
treeab0440dc73efaefdc90a12ce9892a66e6fd7cff3 /lib/Analysis/RegionStore.cpp
parent77cfac623178d0c16e16e2f171d20b0fea8fde30 (diff)
Implement load from struct region. Instead of returning an UnknownVal(), we create a CompoundVal by loading from each field of the struct.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58494 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r--lib/Analysis/RegionStore.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index d5fb4d2a9a..c2a5da7289 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -113,6 +113,12 @@ private:
Store InitializeArrayToUndefined(Store store, QualType T, MemRegion* BaseR);
Store InitializeStructToUndefined(Store store, QualType T, MemRegion* BaseR);
+
+ SVal RetrieveStruct(Store store, const TypedRegion* R);
+
+ // Utility methods.
+ BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); }
+ ASTContext& getContext() { return StateMgr.getContext(); }
};
} // end anonymous namespace
@@ -224,6 +230,10 @@ SVal RegionStoreManager::Retrieve(Store S, Loc L, QualType T) {
const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion();
assert(R && "bad region");
+ if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
+ if (TR->getType(getContext())->isStructureType())
+ return RetrieveStruct(S, TR);
+
RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(S));
RegionBindingsTy::data_type* V = B.lookup(R);
return V ? *V : UnknownVal();
@@ -244,6 +254,29 @@ SVal RegionStoreManager::Retrieve(Store S, Loc L, QualType T) {
}
}
+SVal RegionStoreManager::RetrieveStruct(Store store, const TypedRegion* R) {
+ QualType T = R->getType(getContext());
+ assert(T->isStructureType());
+
+ const RecordType* RT = cast<RecordType>(T.getTypePtr());
+ RecordDecl* RD = RT->getDecl();
+ assert(RD->isDefinition());
+
+ llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList();
+
+ for (int i = RD->getNumMembers() - 1; i >= 0; --i) {
+ FieldRegion* FR = MRMgr.getFieldRegion(RD->getMember(i), R);
+ RegionBindingsTy B(static_cast<const RegionBindingsTy::TreeTy*>(store));
+ RegionBindingsTy::data_type* data = B.lookup(R);
+
+ SVal FieldValue = data ? *data : UnknownVal();
+
+ StructVal = getBasicVals().consVals(FieldValue, StructVal);
+ }
+
+ return NonLoc::MakeCompoundVal(T, StructVal, getBasicVals());
+}
+
Store RegionStoreManager::Bind(Store store, Loc LV, SVal V) {
if (LV.getSubKind() == loc::SymbolValKind)
return store;