[cfe-commits] r58496 - /cfe/trunk/lib/Analysis/RegionStore.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Fri Oct 31 01:10:03 PDT 2008
Author: zhongxingxu
Date: Fri Oct 31 03:10:01 2008
New Revision: 58496
URL: http://llvm.org/viewvc/llvm-project?rev=58496&view=rev
Log:
Implement BindStruct and fix a bug in RetriveStruct.
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=58496&r1=58495&r2=58496&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Fri Oct 31 03:10:01 2008
@@ -115,7 +115,7 @@
Store InitializeStructToUndefined(Store store, QualType T, MemRegion* BaseR);
SVal RetrieveStruct(Store store, const TypedRegion* R);
-
+ Store BindStruct(Store store, const TypedRegion* R, SVal V);
// Utility methods.
BasicValueFactory& getBasicVals() { return StateMgr.getBasicVals(); }
ASTContext& getContext() { return StateMgr.getContext(); }
@@ -267,7 +267,7 @@
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);
+ RegionBindingsTy::data_type* data = B.lookup(FR);
SVal FieldValue = data ? *data : UnknownVal();
@@ -285,8 +285,11 @@
const MemRegion* R = cast<loc::MemRegionVal>(LV).getRegion();
- if (!R)
- return store;
+ assert(R);
+
+ if (const TypedRegion* TR = dyn_cast<TypedRegion>(R))
+ if (TR->getType(getContext())->isStructureType())
+ return BindStruct(store, TR, V);
RegionBindingsTy B = GetRegionBindings(store);
return V.isUnknown()
@@ -294,6 +297,32 @@
: RBFactory.Add(B, R, V).getRoot();
}
+Store RegionStoreManager::BindStruct(Store store, const TypedRegion* R, SVal V){
+ QualType T = R->getType(getContext());
+ assert(T->isStructureType());
+
+ const RecordType* RT = cast<RecordType>(T.getTypePtr());
+ RecordDecl* RD = RT->getDecl();
+ assert(RD->isDefinition());
+
+ RegionBindingsTy B = GetRegionBindings(store);
+
+ nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V);
+
+ nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
+ RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end();
+
+ for (; FI != FE; ++FI, ++VI) {
+ assert(VI != VE);
+
+ FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
+
+ B = RBFactory.Add(B, FR, *VI);
+ }
+
+ return B.getRoot();
+}
+
Store RegionStoreManager::getInitialStore() {
typedef LiveVariables::AnalysisDataTy LVDataTy;
LVDataTy& D = StateMgr.getLiveVariables().getAnalysisData();
More information about the cfe-commits
mailing list