This revision was automatically updated to reflect the committed changes. Closed by commit rC339088: [analyzer] pr37204: Take signedness into account in getTruthValue(). (authored by dergachev, committed by ).
Changed prior to commit: https://reviews.llvm.org/D50363?vs=159435&id=159446#toc Repository: rC Clang https://reviews.llvm.org/D50363 Files: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h test/Analysis/casts.c Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h @@ -211,7 +211,8 @@ } 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) { Index: test/Analysis/casts.c =================================================================== --- test/Analysis/casts.c +++ test/Analysis/casts.c @@ -182,3 +182,9 @@ c += 1; } } + +void testSwitchWithSizeofs() { + switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}} + case sizeof(char):; // no-crash + } +}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h @@ -211,7 +211,8 @@ } 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) { Index: test/Analysis/casts.c =================================================================== --- test/Analysis/casts.c +++ test/Analysis/casts.c @@ -182,3 +182,9 @@ c += 1; } } + +void testSwitchWithSizeofs() { + switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}} + case sizeof(char):; // no-crash + } +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits