]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix RangeConstraintManager's pinning of single value ranges.
authorPierre Gousseau <pierregousseau14@gmail.com>
Tue, 12 Jan 2016 10:40:45 +0000 (10:40 +0000)
committerPierre Gousseau <pierregousseau14@gmail.com>
Tue, 12 Jan 2016 10:40:45 +0000 (10:40 +0000)
This fix a bug in RangeSet::pin causing single value ranges to be considered non conventionally ordered.

Differential Revision: http://reviews.llvm.org/D12901

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

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

index 0a2b2e64a142ae33575a1f9073bde98ecb3e42b1..77b0ad32b6b7c3ea4f1137089677353ded49c802 100644 (file)
@@ -171,7 +171,7 @@ private:
       case APSIntType::RTR_Below:
         // The entire range is outside the symbol's set of possible values.
         // If this is a conventionally-ordered range, the state is infeasible.
-        if (Lower < Upper)
+        if (Lower <= Upper)
           return false;
 
         // However, if the range wraps around, it spans all possible values.
@@ -222,7 +222,7 @@ private:
       case APSIntType::RTR_Above:
         // The entire range is outside the symbol's set of possible values.
         // If this is a conventionally-ordered range, the state is infeasible.
-        if (Lower < Upper)
+        if (Lower <= Upper)
           return false;
 
         // However, if the range wraps around, it spans all possible values.
index f056cb85a33fd51fcd978bf690e4399670f9d7e5..682369cce66ff2eda27a777d5deb363d84cf4520 100644 (file)
@@ -73,6 +73,16 @@ void f7(long foo)
     clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
 
+void f8(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1L == 0L)
+    clang_analyzer_warnIfReached(); // no-warning
+  else
+    clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
 void f9(long foo)
 {
   unsigned index = -1;
@@ -93,6 +103,16 @@ void f10(long foo)
     clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
 
+void f11(long foo)
+{
+  unsigned index = -1;
+  if (index < foo) index = foo;
+  if (index + 1UL == 0L)
+    clang_analyzer_warnIfReached(); // no-warning
+  else
+    clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
 void f12(long foo)
 {
   unsigned index = -1;
@@ -103,6 +123,16 @@ void f12(long foo)
     clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
 }
 
+void f13(int foo)
+{
+  unsigned short index = -1;
+  if (index < foo) index = foo;
+  if (index + 1 == 0)
+    clang_analyzer_warnIfReached(); // no-warning
+  else
+    clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
 void f14(long foo)
 {
   unsigned index = -1;