alexshap created this revision. alexshap created this object with visibility "All Users".
This diff replaces getTypeSize(CondE->getType())) with getIntWidth(CondE->getType())). These calls are not equivalent for bool https://clang.llvm.org/doxygen/ASTContext_8cpp_source.html#l08444 and the analyzer crashes. Add a test case. Repository: rL LLVM https://reviews.llvm.org/D32328 Files: lib/StaticAnalyzer/Core/ExprEngine.cpp test/Analysis/enum.cpp Index: test/Analysis/enum.cpp =================================================================== --- test/Analysis/enum.cpp +++ test/Analysis/enum.cpp @@ -24,3 +24,16 @@ 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; +} Index: lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1904,7 +1904,7 @@ // 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;
Index: test/Analysis/enum.cpp =================================================================== --- test/Analysis/enum.cpp +++ test/Analysis/enum.cpp @@ -24,3 +24,16 @@ 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; +} Index: lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1904,7 +1904,7 @@ // 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits