diff options
-rw-r--r-- | clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h | 3 | ||||
-rw-r--r-- | clang/test/Analysis/casts.c | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h index b72b158194c..1c5d4eb2de3 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h +++ b/clang/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/clang/test/Analysis/casts.c b/clang/test/Analysis/casts.c index 86fb7da58ec..88bdc55908e 100644 --- a/clang/test/Analysis/casts.c +++ b/clang/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 + } +} |