[cfe-commits] r58506 - /cfe/trunk/lib/Analysis/RegionStore.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Fri Oct 31 03:53:02 PDT 2008
Author: zhongxingxu
Date: Fri Oct 31 05:53:01 2008
New Revision: 58506
URL: http://llvm.org/viewvc/llvm-project?rev=58506&view=rev
Log:
Implement struct initialization for SCA.
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=58506&r1=58505&r2=58506&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Fri Oct 31 05:53:01 2008
@@ -113,6 +113,7 @@
Store InitializeArray(Store store, TypedRegion* R, SVal Init);
Store InitializeArrayToUndefined(Store store, QualType T, MemRegion* BaseR);
+ Store InitializeStruct(Store store, TypedRegion* R, SVal Init);
Store InitializeStructToUndefined(Store store, QualType T, MemRegion* BaseR);
SVal RetrieveStruct(Store store, const TypedRegion* R);
@@ -409,7 +410,10 @@
store = InitializeArray(store, VR, InitVal);
} else if (T->isStructureType()) {
- store = InitializeStructToUndefined(store, T, VR);
+ if (!Ex)
+ store = InitializeStructToUndefined(store, T, VR);
+ else
+ store = InitializeStruct(store, VR, InitVal);
}
// Other types of local variables are not handled yet.
@@ -480,6 +484,48 @@
return store;
}
+Store RegionStoreManager::InitializeStruct(Store store, TypedRegion* R,
+ SVal Init) {
+ QualType T = R->getType(getContext());
+ assert(T->isStructureType());
+
+ RecordType* RT = cast<RecordType>(T.getTypePtr());
+ RecordDecl* RD = RT->getDecl();
+ assert(RD->isDefinition());
+
+ nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init);
+ nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end();
+ RecordDecl::field_iterator FI = RD->field_begin(), FE = RD->field_end();
+
+ for (; FI != FE; ++FI) {
+ QualType FTy = (*FI)->getType();
+ FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
+
+ if (Loc::IsLocType(FTy) || FTy->isIntegerType()) {
+ if (VI != VE) {
+ store = Bind(store, loc::MemRegionVal(FR), *VI);
+ ++VI;
+ } else
+ store = Bind(store, loc::MemRegionVal(FR), UndefinedVal());
+ }
+ else if (FTy->isArrayType()) {
+ if (VI != VE) {
+ store = InitializeArray(store, FR, *VI);
+ ++VI;
+ } else
+ store = InitializeArrayToUndefined(store, FTy, FR);
+ }
+ else if (FTy->isStructureType()) {
+ if (VI != VE) {
+ store = InitializeStruct(store, FR, *VI);
+ ++VI;
+ } else
+ store = InitializeStructToUndefined(store, FTy, FR);
+ }
+ }
+ return store;
+}
+
Store RegionStoreManager::InitializeStructToUndefined(Store store, QualType T,
MemRegion* BaseR) {
QualType CT = StateMgr.getContext().getCanonicalType(T);
More information about the cfe-commits
mailing list