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

Alexander Shaposhnikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 20 18:18:25 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL300936: [analyzer] Fix assert in ExprEngine::processSwitch (authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D32328?vs=96060&id=96070#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32328

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


Index: cfe/trunk/test/Analysis/enum.cpp
===================================================================
--- cfe/trunk/test/Analysis/enum.cpp
+++ cfe/trunk/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: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1904,8 +1904,8 @@
 
     // 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;
     if (const Expr *E = Case->getRHS())


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


More information about the cfe-commits mailing list