[analyzer] Fix assert in ExprEngine::processSwitch

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

llvm-svn: 300936
This commit is contained in:
Alexander Shaposhnikov 2017-04-21 01:05:26 +00:00
parent e03dc7d754
commit 015da3534a
2 changed files with 15 additions and 2 deletions

View 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())

View 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;
}