]> granicus.if.org Git - clang/commitdiff
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337769 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 1d2b94d6f7671387b31e04958687976c9718ea6b..e8c7bdbde385de6f9f00ac3ffdb221129e23ca7d 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 548b4223b6a235dae83c8c87d7432d5af02abd99..49db822aa138e8dce569031588b3bed7c0456d0f 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) {}
+}