diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-03-04 00:13:10 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-03-04 00:13:10 +0000 |
commit | 1cb151eadee0ef1944bd9a16aa4348ead7160259 (patch) | |
tree | 7f4b40fea12d587c94152a4fbd7768d0f8b9d838 | |
parent | 02c4d2d3835ccc744f2092885256ec5ee1498be3 (diff) |
Add "GetSValAsScalarOrLoc" methods to GRState/GRStateRef that only perform a
retrieval from the store/environment for locations or scalar types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65982 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Analysis/PathSensitive/GRState.h | 31 | ||||
-rw-r--r-- | lib/Analysis/GRState.cpp | 4 |
2 files changed, 33 insertions, 2 deletions
diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h index ac474edfdf..b3f4dea860 100644 --- a/include/clang/Analysis/PathSensitive/GRState.h +++ b/include/clang/Analysis/PathSensitive/GRState.h @@ -407,6 +407,17 @@ public: SVal GetSVal(const GRState* St, Stmt* Ex) { return St->getEnvironment().GetSVal(Ex, BasicVals); } + + SVal GetSValAsScalarOrLoc(const GRState* state, const Stmt *S) { + if (const Expr *Ex = dyn_cast<Expr>(S)) { + QualType T = Ex->getType(); + if (Loc::IsLocType(T) || T->isIntegerType()) + return GetSVal(state, S); + } + + return UnknownVal(); + } + SVal GetSVal(const GRState* St, const Stmt* Ex) { return St->getEnvironment().GetSVal(const_cast<Stmt*>(Ex), BasicVals); @@ -416,6 +427,8 @@ public: return St->getEnvironment().GetBlkExprSVal(Ex, BasicVals); } + + const GRState* BindExpr(const GRState* St, Stmt* Ex, SVal V, bool isBlkExpr, bool Invalidate) { @@ -473,6 +486,16 @@ public: SVal GetSVal(const GRState* state, const MemRegion* R) { return StoreMgr->Retrieve(state, loc::MemRegionVal(R)); } + + SVal GetSValAsScalarOrLoc(const GRState* state, const MemRegion *R) { + if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) { + QualType T = TR->getRValueType(getContext()); + if (Loc::IsLocType(T) || T->isIntegerType()) + return GetSVal(state, R); + } + + return UnknownVal(); + } const GRState* BindLoc(const GRState* St, Loc LV, SVal V) { return StoreMgr->Bind(St, LV, V); @@ -637,6 +660,10 @@ public: return Mgr->GetBlkExprSVal(St, Ex); } + SVal GetSValAsScalarOrLoc(const Expr *Ex) { + return Mgr->GetSValAsScalarOrLoc(St, Ex); + } + SVal GetSVal(Loc LV, QualType T = QualType()) { return Mgr->GetSVal(St, LV, T); } @@ -645,6 +672,10 @@ public: return Mgr->GetSVal(St, R); } + SVal GetSValAsScalarOrLoc(const MemRegion *R) { + return Mgr->GetSValAsScalarOrLoc(St, R); + } + GRStateRef BindExpr(Stmt* Ex, SVal V, bool isBlkExpr, bool Invalidate) { return GRStateRef(Mgr->BindExpr(St, Ex, V, isBlkExpr, Invalidate), *Mgr); } diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp index eb6b1b5cfa..85a85f207d 100644 --- a/lib/Analysis/GRState.cpp +++ b/lib/Analysis/GRState.cpp @@ -257,7 +257,7 @@ bool ScanReachableSymbols::scan(SVal val) { } bool ScanReachableSymbols::scan(const MemRegion *R) { - if (visited.count(R)) + if (isa<MemSpaceRegion>(R) || visited.count(R)) return true; visited.insert(R); @@ -273,7 +273,7 @@ bool ScanReachableSymbols::scan(const MemRegion *R) { return false; // Now look at the binding to this region (if any). - if (!scan(state.GetSVal(R))) + if (!scan(state.GetSValAsScalarOrLoc(R))) return false; // Now look at the subregions. |