From: Artem Dergachev Date: Tue, 7 Aug 2018 02:27:38 +0000 (+0000) Subject: [analyzer] pr37204: Take signedness into account in getTruthValue(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d922539bac169bd1dcca808671873ed93eee5901;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339088 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h b/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h index b72b158194..1c5d4eb2de 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h @@ -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) { diff --git a/test/Analysis/casts.c b/test/Analysis/casts.c index 86fb7da58e..88bdc55908 100644 --- a/test/Analysis/casts.c +++ b/test/Analysis/casts.c @@ -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 + } +}