diff options
| author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-03-02 07:52:23 +0000 |
|---|---|---|
| committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-03-02 07:52:23 +0000 |
| commit | e7d14932160bcbb7177551da43b4c1aa6e30bc1c (patch) | |
| tree | a9be16d6d06518bca4836582a9a65cbb9a453c5c /clang/lib/Analysis/RegionStore.cpp | |
| parent | b3921bf12e0278668f0338f56c30986088d7f517 (diff) | |
| download | bcm5719-llvm-e7d14932160bcbb7177551da43b4c1aa6e30bc1c.tar.gz bcm5719-llvm-e7d14932160bcbb7177551da43b4c1aa6e30bc1c.zip | |
Initial support for pointer arithmetic. Only support concrete indexes and
offsets for now.
llvm-svn: 65814
Diffstat (limited to 'clang/lib/Analysis/RegionStore.cpp')
| -rw-r--r-- | clang/lib/Analysis/RegionStore.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp index e6e530bc0f0..7ab54b8b253 100644 --- a/clang/lib/Analysis/RegionStore.cpp +++ b/clang/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"); |

