[cfe-commits] r65814 - in /cfe/trunk: include/clang/Analysis/PathSensitive/Store.h lib/Analysis/GRSimpleVals.cpp lib/Analysis/RegionStore.cpp
Ted Kremenek
kremenek at apple.com
Mon Mar 2 11:17:04 PST 2009
Test case please.
On Mar 1, 2009, at 11:52 PM, Zhongxing Xu wrote:
> Author: zhongxingxu
> Date: Mon Mar 2 01:52:23 2009
> New Revision: 65814
>
> URL: http://llvm.org/viewvc/llvm-project?rev=65814&view=rev
> Log:
> Initial support for pointer arithmetic. Only support concrete
> indexes and
> offsets for now.
>
> Modified:
> cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
> cfe/trunk/lib/Analysis/GRSimpleVals.cpp
> cfe/trunk/lib/Analysis/RegionStore.cpp
>
> Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Store.h?rev=65814&r1=65813&r2=65814&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Analysis/PathSensitive/Store.h (original)
> +++ cfe/trunk/include/clang/Analysis/PathSensitive/Store.h Mon Mar
> 2 01:52:23 2009
> @@ -112,6 +112,11 @@
> /// casted and 'CastToTy' the result type of the cast.
> virtual CastResult CastRegion(const GRState* state, const
> MemRegion* R,
> QualType CastToTy) = 0;
> +
> + /// EvalBinOp - Perform pointer arithmetic.
> + virtual SVal EvalBinOp(BinaryOperator::Opcode Op, Loc L, NonLoc
> R) {
> + return UnknownVal();
> + }
>
> /// getSelfRegion - Returns the region for the 'self' (Objective-
> C) or
> /// 'this' object (C++). When used when analyzing a normal
> function this
>
> Modified: cfe/trunk/lib/Analysis/GRSimpleVals.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRSimpleVals.cpp?rev=65814&r1=65813&r2=65814&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
> +++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Mon Mar 2 01:52:23 2009
> @@ -265,7 +265,8 @@
>
> SVal GRSimpleVals::EvalBinOp(GRExprEngine& Eng,
> BinaryOperator::Opcode Op,
> Loc L, NonLoc R) {
> - return UnknownVal();
> + // Delegate pointer arithmetic to store manager.
> + return Eng.getStoreManager().EvalBinOp(Op, L, R);
> }
>
> // Equality operators for Locs.
>
> Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=65814&r1=65813&r2=65814&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
> +++ cfe/trunk/lib/Analysis/RegionStore.cpp Mon Mar 2 01:52:23 2009
> @@ -170,6 +170,8 @@
> 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 @@
> 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");
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list