[cfe-commits] r58494 - /cfe/trunk/lib/Analysis/RegionStore.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Fri Oct 31 00:16:08 PDT 2008
Author: zhongxingxu
Date: Fri Oct 31 02:16:08 2008
New Revision: 58494
URL: http://llvm.org/viewvc/llvm-project?rev=58494&view=rev
Log:
Implement load from struct region. Instead of returning an UnknownVal(), we create a CompoundVal by loading from each field of the struct.
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=58494&r1=58493&r2=58494&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Fri Oct 31 02:16:08 2008
@@ -113,6 +113,12 @@
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 @@
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::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;
More information about the cfe-commits
mailing list