]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix assert in ExprEngine::processSwitch
authorAlexander Shaposhnikov <shal1t712@gmail.com>
Fri, 21 Apr 2017 01:05:26 +0000 (01:05 +0000)
committerAlexander Shaposhnikov <shal1t712@gmail.com>
Fri, 21 Apr 2017 01:05:26 +0000 (01:05 +0000)
This diff replaces getTypeSize(CondE->getType()))
with getIntWidth(CondE->getType())) in ExprEngine::processSwitch.
These calls are not equivalent for bool, see ASTContext.cpp
Add a test case.

Test plan:
make check-clang-analysis
make check-clang

Differential revision: https://reviews.llvm.org/D32328

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300936 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 9e6ec09010e91435342f0e861829fbb0b67165b3..8ee34190891adda0a369771d3a317b614832c8a7 100644 (file)
@@ -1904,8 +1904,8 @@ void ExprEngine::processSwitch(SwitchNodeBuilder& builder) {
 
     // 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())
index e26b8f00d98ca903ff195ebfd4f306bac1033bee..b561e65ac86ea494536073619b0d44c7fa36ad80 100644 (file)
@@ -24,3 +24,16 @@ void testCasting(int i) {
     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;
+}