From a339cd66be6202c6e86916f52a347d0289bf2eea Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Sat, 23 Mar 2013 01:21:29 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177805 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/SVals.cpp | 7 +++---- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/StaticAnalyzer/Core/SVals.cpp b/lib/StaticAnalyzer/Core/SVals.cpp index da52a90ec5..38e216f28c 100644 --- a/lib/StaticAnalyzer/Core/SVals.cpp +++ b/lib/StaticAnalyzer/Core/SVals.cpp @@ -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(); } diff --git a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index 3d4262b789..5cc8926a44 100644 --- a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -582,10 +582,11 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state, if (Optional rInt = rhs.getAs()) { SVal ResultVal = lhs.castAs().evalBinOp(BasicVals, op, *rInt); - if (Optional Result = ResultVal.getAs()) - return evalCastFromLoc(*Result, resultTy); - else - return UnknownVal(); + if (Optional Result = ResultVal.getAs()) + return evalCastFromNonLoc(*Result, resultTy); + + assert(!ResultVal.getAs() && "Loc-Loc ops should not produce Locs"); + return UnknownVal(); } // Special case comparisons against NULL. -- 2.40.0