diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2018-08-07 02:27:38 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2018-08-07 02:27:38 +0000 |
commit | afdce6684eff7f25ba9a40dcf41570bc3c20e2bd (patch) | |
tree | 4084239e48afcbbcdafe88a3f262ddb89d9efbbc | |
parent | 5a5b86742208bd6fbc909b0313d80eb402caaad3 (diff) | |
download | bcm5719-llvm-afdce6684eff7f25ba9a40dcf41570bc3c20e2bd.tar.gz bcm5719-llvm-afdce6684eff7f25ba9a40dcf41570bc3c20e2bd.zip |
[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
-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 + } +} |