[analyzer] pr37204: Take signedness into account in getTruthValue().

It now actually produces a signed APSInt when the QualType passed into it is
signed, which is what any caller would expect.

Fixes a couple of crashes.

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

llvm-svn: 339088
This commit is contained in:
Artem Dergachev 2018-08-07 02:27:38 +00:00
parent 5a5b867422
commit afdce6684e
2 changed files with 8 additions and 1 deletions

View File

@ -211,7 +211,8 @@ public:
}
const llvm::APSInt &getTruthValue(bool b, QualType T) {
return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
T->isUnsignedIntegerOrEnumerationType());
}
const llvm::APSInt &getTruthValue(bool b) {

View File

@ -182,3 +182,9 @@ void testLocNonLocSymbolRemainder(int a, int *b) {
c += 1;
}
}
void testSwitchWithSizeofs() {
switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}}
case sizeof(char):; // no-crash
}
}