From: Zhongxing Xu Date: Thu, 9 Apr 2009 07:39:46 +0000 (+0000) Subject: stop using loc::SymbolVal and clean up code with new API. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c565b63a7905347a51249fafbcaf41b177a22bf0;p=clang stop using loc::SymbolVal and clean up code with new API. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68703 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/SVals.h b/include/clang/Analysis/PathSensitive/SVals.h index 9d9d9d8091..f3a2d369e7 100644 --- a/include/clang/Analysis/PathSensitive/SVals.h +++ b/include/clang/Analysis/PathSensitive/SVals.h @@ -226,8 +226,6 @@ public: static Loc MakeVal(AddrLabelExpr* E); - static Loc MakeVal(SymbolRef sym); - static Loc MakeNull(BasicValueFactory &BasicVals); // Implement isa support. diff --git a/lib/Analysis/GRSimpleVals.cpp b/lib/Analysis/GRSimpleVals.cpp index dfc9d4eb1c..44e76555f9 100644 --- a/lib/Analysis/GRSimpleVals.cpp +++ b/lib/Analysis/GRSimpleVals.cpp @@ -260,32 +260,20 @@ SVal GRSimpleVals::EvalBinOp(GRExprEngine& Eng, BinaryOperator::Opcode Op, } } -// Pointer arithmetic. -static Loc StripViews(Loc X) { - if (isa(X)) { - const SymbolicRegion *Region = - cast(X).getRegion()->getAs(); - - if (Region) - return Loc::MakeVal(Region->getSymbol()); - } - - return X; -} - SVal GRSimpleVals::EvalBinOp(GRExprEngine& Eng, BinaryOperator::Opcode Op, Loc L, NonLoc R) { // Delegate pointer arithmetic to store manager. return Eng.getStoreManager().EvalBinOp(Op, L, R); } -// Equality operators for Locs. +// Equality operators for Locs. +// FIXME: All this logic will be revamped when we have MemRegion::getLocation() +// implemented. SVal GRSimpleVals::EvalEQ(GRExprEngine& Eng, Loc L, Loc R) { BasicValueFactory& BasicVals = Eng.getBasicVals(); -TryAgain: switch (L.getSubKind()) { default: @@ -335,14 +323,15 @@ TryAgain: } case loc::MemRegionKind: { - // See if 'L' and 'R' both wrap symbols. - Loc LTmp = StripViews(L); - Loc RTmp = StripViews(R); - - if (LTmp != L || RTmp != R) { - L = LTmp; - R = RTmp; - goto TryAgain; + if (SymbolRef LSym = L.getAsLocSymbol()) { + if (isa(R)) { + const SymIntExpr *SE = + Eng.getSymbolManager().getSymIntExpr(LSym, BinaryOperator::EQ, + cast(R).getValue(), + Eng.getContext().IntTy); + + return nonloc::SymExprVal(SE); + } } } @@ -360,7 +349,6 @@ SVal GRSimpleVals::EvalNE(GRExprEngine& Eng, Loc L, Loc R) { BasicValueFactory& BasicVals = Eng.getBasicVals(); -TryAgain: switch (L.getSubKind()) { default: @@ -407,15 +395,16 @@ TryAgain: } case loc::MemRegionKind: { - // See if 'L' and 'R' both wrap symbols. - Loc LTmp = StripViews(L); - Loc RTmp = StripViews(R); - - if (LTmp != L || RTmp != R) { - L = LTmp; - R = RTmp; - goto TryAgain; + if (SymbolRef LSym = L.getAsLocSymbol()) { + if (isa(R)) { + const SymIntExpr* SE = + Eng.getSymbolManager().getSymIntExpr(LSym, BinaryOperator::NE, + cast(R).getValue(), + Eng.getContext().IntTy); + return nonloc::SymExprVal(SE); + } } + // Fall through: } case loc::FuncValKind: diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp index ddb2da611f..b78eea72c9 100644 --- a/lib/Analysis/SVals.cpp +++ b/lib/Analysis/SVals.cpp @@ -338,8 +338,6 @@ Loc Loc::MakeVal(const MemRegion* R) { return loc::MemRegionVal(R); } Loc Loc::MakeVal(AddrLabelExpr* E) { return loc::GotoLabel(E->getLabel()); } -Loc Loc::MakeVal(SymbolRef sym) { return loc::SymbolVal(sym); } - Loc Loc::MakeNull(BasicValueFactory &BasicVals) { return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth()); }