aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/RegionStore.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2009-03-02 07:52:23 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2009-03-02 07:52:23 +0000
commit94aa6c16e7404b2ff83a6f0ae7db8a758d389fc4 (patch)
tree856ec6c18d7e758b0f0b2b92c427a5e1469ffd38 /lib/Analysis/RegionStore.cpp
parent82573ee7419091e5ec87e2f4fa254c7a285781d6 (diff)
Initial support for pointer arithmetic. Only support concrete indexes and
offsets for now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65814 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionStore.cpp')
-rw-r--r--lib/Analysis/RegionStore.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index e6e530bc0f..7ab54b8b25 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -170,6 +170,8 @@ public:
CastResult CastRegion(const GRState* state, const MemRegion* R,
QualType CastToTy);
+ SVal EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R);
+
/// The high level logic for this method is this:
/// Retrieve (L)
/// if L has binding
@@ -551,6 +553,33 @@ RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,
return CastResult(AddRegionView(state, ViewR, R), ViewR);
}
+SVal RegionStoreManager::EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc R) {
+ // Assume the base location is MemRegionVal(ElementRegion).
+
+ if (!isa<loc::MemRegionVal>(L)) {
+ return UnknownVal();
+ }
+
+ const MemRegion* MR = cast<loc::MemRegionVal>(L).getRegion();
+
+ const ElementRegion* ER = cast<ElementRegion>(MR);
+ SVal Idx = ER->getIndex();
+
+ nonloc::ConcreteInt* Base = dyn_cast<nonloc::ConcreteInt>(&Idx);
+ nonloc::ConcreteInt* Offset = dyn_cast<nonloc::ConcreteInt>(&R);
+
+ // Only support concrete integer indexes for now.
+ if (Base && Offset) {
+ SVal NewIdx = Base->EvalBinOp(getBasicVals(), Op, *Offset);
+
+ const MemRegion* NewER = MRMgr.getElementRegion(NewIdx,
+ ER->getArrayRegion());
+ return Loc::MakeVal(NewER);
+
+ } else
+ return UnknownVal();
+}
+
SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) {
assert(!isa<UnknownVal>(L) && "location unknown");
assert(!isa<UndefinedVal>(L) && "location undefined");