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
// 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())
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;
+}