[PATCH] D32328: [analyzer] Fix assert in ExprEngine::processSwitch

Alexander Shaposhnikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 20 17:01:13 PDT 2017


alexshap created this revision.
alexshap created this object with visibility "All Users".

This diff replaces getTypeSize(CondE->getType())) with getIntWidth(CondE->getType())).
These calls are not equivalent for bool https://clang.llvm.org/doxygen/ASTContext_8cpp_source.html#l08444 
and the analyzer crashes. 
Add a test case.


Repository:
  rL LLVM

https://reviews.llvm.org/D32328

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/enum.cpp


Index: test/Analysis/enum.cpp
===================================================================
--- test/Analysis/enum.cpp
+++ test/Analysis/enum.cpp
@@ -24,3 +24,16 @@
     clang_analyzer_eval(j == 0); // expected-warning{{FALSE}}
   }
 }
+
+enum class EnumBool : bool {
+  F = false,
+  T = true
+};
+
+bool testNoCrashOnSwitchEnumBool(EnumBool E) {
+  switch (E) {
+  case EnumBool::F:
+    return false;
+  }
+  return true;
+}
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1904,7 +1904,7 @@
 
     // Evaluate the LHS of the case value.
     llvm::APSInt V1 = Case->getLHS()->EvaluateKnownConstInt(getContext());
-    assert(V1.getBitWidth() == getContext().getTypeSize(CondE->getType()));
+    assert(V1.getBitWidth() == getContext().getIntWidth(CondE->getType()));
 
     // Get the RHS of the case, if it exists.
     llvm::APSInt V2;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32328.96060.patch
Type: text/x-patch
Size: 1003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170421/84fe57d8/attachment-0001.bin>


More information about the cfe-commits mailing list