r258039 - [analyzer] Fix an off-by-one in evalIntegralCast()
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 18 02:17:18 PST 2016
Author: dergachev
Date: Mon Jan 18 04:17:16 2016
New Revision: 258039
URL: http://llvm.org/viewvc/llvm-project?rev=258039&view=rev
Log:
[analyzer] Fix an off-by-one in evalIntegralCast()
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
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
cfe/trunk/test/Analysis/bool-assignment.c
Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=258039&r1=258038&r2=258039&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Mon Jan 18 04:17:16 2016
@@ -451,7 +451,7 @@ SVal SValBuilder::evalIntegralCast(Progr
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) {
Modified: cfe/trunk/test/Analysis/bool-assignment.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/bool-assignment.c?rev=258039&r1=258038&r2=258039&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/bool-assignment.c (original)
+++ cfe/trunk/test/Analysis/bool-assignment.c Mon Jan 18 04:17:16 2016
@@ -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;
More information about the cfe-commits
mailing list