forked from OSchip/llvm-project
[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:
parent
e03dc7d754
commit
015da3534a
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue