From: Zhongxing Xu Date: Sun, 16 Nov 2008 07:06:26 +0000 (+0000) Subject: Enhance modularization: return a pair to let GRExprEngine modify the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cb529b542a6c473251d15fdd637b3230906ea1dc;p=clang Enhance modularization: return a pair to let GRExprEngine modify the environment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59407 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/Store.h b/include/clang/Analysis/PathSensitive/Store.h index 06c49cb85c..e31b6d4ddc 100644 --- a/include/clang/Analysis/PathSensitive/Store.h +++ b/include/clang/Analysis/PathSensitive/Store.h @@ -81,8 +81,8 @@ public: /// conversions between arrays and pointers. virtual SVal ArrayToPointer(SVal Array) = 0; - virtual const GRState* CastRegion(const GRState* St, SVal VoidPtr, - QualType CastToTy, Stmt* CastE) = 0; + virtual std::pair + CastRegion(const GRState* St, SVal VoidPtr, QualType CastToTy, Stmt* CastE)=0; /// getSelfRegion - Returns the region for the 'self' (Objective-C) or /// 'this' object (C++). When used when analyzing a normal function this diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index 8b5ef6ee86..ae6febff7b 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -66,9 +66,9 @@ public: /// conversions between arrays and pointers. SVal ArrayToPointer(SVal Array) { return Array; } - const GRState* CastRegion(const GRState* St, SVal VoidPtr, QualType CastToTy, - Stmt* CastE) { - return St; + std::pair + CastRegion(const GRState* St, SVal VoidPtr, QualType CastToTy, Stmt* CastE) { + return std::pair(St, UnknownVal()); } diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index e002c13637..fe7d6f9426 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -1698,11 +1698,15 @@ void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){ assert(Loc::IsLocType(ExTy)); // Delegate to store manager. - const GRState* NewSt = getStoreManager().CastRegion(St, V, T, CastE); + std::pair Res = + getStoreManager().CastRegion(St, V, T, CastE); + + const GRState* NewSt = Res.first; + SVal NewPtr = Res.second; // If no new region is created, fall through to the default case. if (NewSt != St) { - MakeNode(Dst, CastE, N, NewSt); + MakeNode(Dst, CastE, N, BindExpr(NewSt, CastE, NewPtr)); continue; } } diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 732785c0f7..fab2e60538 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -82,8 +82,8 @@ public: SVal ArrayToPointer(SVal Array); - const GRState* CastRegion(const GRState* St, SVal VoidPtr, - QualType CastToTy, Stmt* CastE); + std::pair + CastRegion(const GRState* St, SVal VoidPtr, QualType CastToTy, Stmt* CastE); SVal Retrieve(Store S, Loc L, QualType T = QualType()); @@ -264,10 +264,9 @@ SVal RegionStoreManager::ArrayToPointer(SVal Array) { return loc::MemRegionVal(ER); } -const GRState* RegionStoreManager::CastRegion(const GRState* St, - SVal VoidPtr, - QualType CastToTy, - Stmt* CastE) { +std::pair +RegionStoreManager::CastRegion(const GRState* St, SVal VoidPtr, + QualType CastToTy, Stmt* CastE) { if (const AllocaRegion* AR = dyn_cast(cast(VoidPtr).getRegion())) { @@ -278,14 +277,13 @@ const GRState* RegionStoreManager::CastRegion(const GRState* St, nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false)); const ElementRegion* ER = MRMgr.getElementRegion(Idx, TR); - St = StateMgr.BindExpr(St, CastE, loc::MemRegionVal(ER)); - // Add a RegionView to base region. - return AddRegionView(St, TR, AR); + return std::pair(AddRegionView(St, TR, AR), + loc::MemRegionVal(ER)); } // Default case. - return St; + return std::pair(St, UnknownVal()); } SVal RegionStoreManager::Retrieve(Store S, Loc L, QualType T) {