summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Gousseau <pierregousseau14@gmail.com>2016-01-12 10:40:45 +0000
committerPierre Gousseau <pierregousseau14@gmail.com>2016-01-12 10:40:45 +0000
commitbdd9da14d653c5b9616cb8562f58513c0c781964 (patch)
tree2cc0e8307aae579bad4ce1d1d967478e8c2ff1a5
parentf617e678e90c85a1fc733ad8ce93ffc51cfd4f72 (diff)
downloadbcm5719-llvm-bdd9da14d653c5b9616cb8562f58513c0c781964.tar.gz
bcm5719-llvm-bdd9da14d653c5b9616cb8562f58513c0c781964.zip
[analyzer] Fix RangeConstraintManager's pinning of single value ranges.
This fix a bug in RangeSet::pin causing single value ranges to be considered non conventionally ordered. Differential Revision: http://reviews.llvm.org/D12901 llvm-svn: 257467
-rw-r--r--clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp4
-rw-r--r--clang/test/Analysis/range_casts.c30
2 files changed, 32 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 0a2b2e64a14..77b0ad32b6b 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -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.
diff --git a/clang/test/Analysis/range_casts.c b/clang/test/Analysis/range_casts.c
index f056cb85a33..682369cce66 100644
--- a/clang/test/Analysis/range_casts.c
+++ b/clang/test/Analysis/range_casts.c
@@ -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;
OpenPOWER on IntegriCloud