[Analyzer] Fix for SValBuilder expressions rearrangement

Expression rearrangement in SValBuilder (see rL329780) crashes with an assert if the type of the integer is different from the type of the symbol. This fix adds a check that prevents rearrangement in such cases.

Differential Revision: https://reviews.llvm.org/D45557

llvm-svn: 330064
This commit is contained in:
Adam Balogh 2018-04-13 20:23:02 +00:00
parent ab40e44ba1
commit 13e186c088
2 changed files with 7 additions and 0 deletions

View File

@ -469,6 +469,8 @@ static Optional<NonLoc> tryRearrange(ProgramStateRef State,
// Initialize SingleTy later with a symbol's type.
} else if (BinaryOperator::isAdditiveOp(Op)) {
SingleTy = ResultTy;
if (LSym->getType() != SingleTy)
return None;
// Substracting unsigned integers is a nightmare.
if (!SingleTy->isSignedIntegerOrEnumerationType())
return None;

View File

@ -929,3 +929,8 @@ void overflow(signed char n, signed char m) {
clang_analyzer_eval(n - 126 == m + 3); // expected-warning{{UNKNOWN}}
}
}
int mixed_integer_types(int x, int y) {
short a = x - 1U;
return a - y;
}