From: Zhongxing Xu Date: Sun, 2 Nov 2008 12:13:30 +0000 (+0000) Subject: 1. When a pointer to struct is used as an argument, GRSimpleVals::EvalCall() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d463d44c6a1c8d6682419aaa9b7eee6ebed62e09;p=clang 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 --- 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(V)) + return BindStructToVal(store, R, UnknownVal()); + nonloc::CompoundVal& CV = cast(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); } }