[analyzer] pr38273: Legalize Loc<>NonLoc comparison symbols.
authorArtem Dergachev <artem.dergachev@gmail.com>
Mon, 23 Jul 2018 23:09:44 +0000 (23:09 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Mon, 23 Jul 2018 23:09:44 +0000 (23:09 +0000)
Remove an assertion in RangeConstraintManager that expects such symbols to never
appear, while admitting that the constraint manager doesn't yet handle them.

Differential Revision: https://reviews.llvm.org/D49703

llvm-svn: 337769

clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
clang/test/Analysis/casts.c

index 1d2b94d..e8c7bdb 100644 (file)
@@ -343,9 +343,11 @@ bool RangeConstraintManager::canReasonAbout(SVal X) const {
       if (BinaryOperator::isEqualityOp(SSE->getOpcode()) ||
           BinaryOperator::isRelationalOp(SSE->getOpcode())) {
         // We handle Loc <> Loc comparisons, but not (yet) NonLoc <> NonLoc.
+        // We've recently started producing Loc <> NonLoc comparisons (that
+        // result from casts of one of the operands between eg. intptr_t and
+        // void *), but we can't reason about them yet.
         if (Loc::isLocType(SSE->getLHS()->getType())) {
-          assert(Loc::isLocType(SSE->getRHS()->getType()));
-          return true;
+          return Loc::isLocType(SSE->getRHS()->getType());
         }
       }
     }
index 548b422..49db822 100644 (file)
@@ -171,3 +171,7 @@ void testCastVoidPtrToIntPtrThroughUIntTypedAssignment() {
   (*((int *)(&x))) = (int)(unsigned *)getVoidPtr();
   *x = 1; // no-crash
 }
+
+void testLocNonLocSymbolAssume(int a, int *b) {
+  if ((int)b < a) {}
+}