Skip to content
Snippets Groups Projects
Commit 6ae3e4a2 authored by Alexander Shaposhnikov's avatar Alexander Shaposhnikov
Browse files

[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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300936 91177308-0d34-0410-b5e6-96231b3b80d8
parent 7a3629bc
No related branches found
No related tags found
No related merge requests found
...@@ -1904,8 +1904,8 @@ void ExprEngine::processSwitch(SwitchNodeBuilder& builder) { ...@@ -1904,8 +1904,8 @@ void ExprEngine::processSwitch(SwitchNodeBuilder& builder) {
// Evaluate the LHS of the case value. // Evaluate the LHS of the case value.
llvm::APSInt V1 = Case->getLHS()->EvaluateKnownConstInt(getContext()); 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. // Get the RHS of the case, if it exists.
llvm::APSInt V2; llvm::APSInt V2;
if (const Expr *E = Case->getRHS()) if (const Expr *E = Case->getRHS())
......
...@@ -24,3 +24,16 @@ void testCasting(int i) { ...@@ -24,3 +24,16 @@ void testCasting(int i) {
clang_analyzer_eval(j == 0); // expected-warning{{FALSE}} 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment