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

Phabricator via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 6 19:28:10 PDT 2018


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
+  }
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50363.159446.patch
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180807/4be6e21f/attachment.bin>


More information about the cfe-commits mailing list