]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix an off-by-one in evalIntegralCast()
authorArtem Dergachev <artem.dergachev@gmail.com>
Mon, 18 Jan 2016 10:17:16 +0000 (10:17 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Mon, 18 Jan 2016 10:17:16 +0000 (10:17 +0000)
Make sure that we do not add SymbolCast at the very boundary of
the range in which the cast would not certainly happen.

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

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

lib/StaticAnalyzer/Core/SValBuilder.cpp
test/Analysis/bool-assignment.c

index 18315225a99d5f031758c223e10c93f337c1d48c..22bc14edd687e9d28d828f2410bba27b8c90ab17 100644 (file)
@@ -451,7 +451,7 @@ SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val,
   NonLoc FromVal = val.castAs<NonLoc>();
   QualType CmpTy = getConditionType();
   NonLoc CompVal =
-      evalBinOpNN(state, BO_LT, FromVal, ToTypeMaxVal, CmpTy).castAs<NonLoc>();
+      evalBinOpNN(state, BO_LE, FromVal, ToTypeMaxVal, CmpTy).castAs<NonLoc>();
   ProgramStateRef IsNotTruncated, IsTruncated;
   std::tie(IsNotTruncated, IsTruncated) = state->assume(CompVal);
   if (!IsNotTruncated && IsTruncated) {
index 0f782fbfd9a9666ab0a1de066241d4a38b2fd276..285569ee11bb46a806491d433299bed0c876d6ab 100644 (file)
@@ -42,6 +42,15 @@ void test_BOOL_initialization(int y) {
     BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
     return;
   }
+  if (y > 200 && y < 250) {
+    // FIXME: Currently we are loosing this warning due to a SymbolCast in RHS.
+    BOOL x = y; // no-warning
+    return;
+  }
+  if (y >= 127 && y < 150) {
+    BOOL x = y; // expected-warning{{Assignment of a non-Boolean value}}
+    return;
+  }
   if (y > 1) {
     BOOL x = y; // expected-warning {{Assignment of a non-Boolean value}}
     return;