[analyzer] Loc-Loc operations (subtraction or comparison) produce a NonLoc.

For two concrete locations, we were producing another concrete location and
then casting it to an integer. We should just create a nonloc::ConcreteInt
to begin with.

No functionality change.

llvm-svn: 177805
This commit is contained in:
Jordan Rose 2013-03-23 01:21:29 +00:00
parent b042cc7822
commit 8eca04b24e
2 changed files with 8 additions and 8 deletions

View File

@ -214,13 +214,12 @@ SVal loc::ConcreteInt::evalBinOp(BasicValueFactory& BasicVals,
BinaryOperator::Opcode Op,
const loc::ConcreteInt& R) const {
assert (Op == BO_Add || Op == BO_Sub ||
(Op >= BO_LT && Op <= BO_NE));
assert(BinaryOperator::isComparisonOp(Op) || Op == BO_Sub);
const llvm::APSInt* X = BasicVals.evalAPSInt(Op, getValue(), R.getValue());
const llvm::APSInt *X = BasicVals.evalAPSInt(Op, getValue(), R.getValue());
if (X)
return loc::ConcreteInt(*X);
return nonloc::ConcreteInt(*X);
else
return UndefinedVal();
}

View File

@ -582,10 +582,11 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
if (Optional<loc::ConcreteInt> rInt = rhs.getAs<loc::ConcreteInt>()) {
SVal ResultVal =
lhs.castAs<loc::ConcreteInt>().evalBinOp(BasicVals, op, *rInt);
if (Optional<Loc> Result = ResultVal.getAs<Loc>())
return evalCastFromLoc(*Result, resultTy);
else
return UnknownVal();
if (Optional<NonLoc> Result = ResultVal.getAs<NonLoc>())
return evalCastFromNonLoc(*Result, resultTy);
assert(!ResultVal.getAs<Loc>() && "Loc-Loc ops should not produce Locs");
return UnknownVal();
}
// Special case comparisons against NULL.