[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

llvm-svn: 258039
This commit is contained in:
Artem Dergachev 2016-01-18 10:17:16 +00:00
parent 836d965168
commit 91c45e8f46
2 changed files with 10 additions and 1 deletions

View 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) {

View 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;