]> granicus.if.org Git - clang/commitdiff
[analyzer] Loc-Loc operations (subtraction or comparison) produce a NonLoc.
authorJordan Rose <jordan_rose@apple.com>
Sat, 23 Mar 2013 01:21:29 +0000 (01:21 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 23 Mar 2013 01:21:29 +0000 (01:21 +0000)
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
lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

index da52a90ec5512cde73b02bded6fb3a98e78c7e00..38e216f28c06df8b1b57c619ea51adb49867d839 100644 (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::APSIntX = 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();
 }
index 3d4262b789c06da6af60b9744e5e5e799043c98d..5cc8926a4449836f7910e0d847c80415b9de838c 100644 (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.