Skip to content

z3 sort equality assertion failed on scoped enum cast to integer. #47570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue Nov 19, 2020 · 4 comments
Closed

z3 sort equality assertion failed on scoped enum cast to integer. #47570

llvmbot opened this issue Nov 19, 2020 · 4 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:static analyzer confirmed Verified by a second party

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2020

Bugzilla Link 48226
Version trunk
OS All
Attachments stack-dump
Reporter LLVM Bugzilla Contributor
CC @steakhal,@devincoughlin,@vabridgers

Extended Description

Test case:

(excerpted from llvm/include/llvm/Analysis/AliasAnalysis.h)

/////////////////////////////////// test.cpp //////////////////////////////

enum class ModRefInfo : unsigned char {
  /// Must is provided for completeness, but no routines will return only
  /// Must today. See definition of Must below.
  Must = 0,
  /// The access may reference the value stored in memory,
  /// a mustAlias relation was found, and no mayAlias or partialAlias found.
  MustRef = 1,
  /// The access may modify the value stored in memory,
  /// a mustAlias relation was found, and no mayAlias or partialAlias found.
  MustMod = 2,
  /// The access may reference, modify or both the value stored in memory,
  /// a mustAlias relation was found, and no mayAlias or partialAlias found.
  MustModRef = MustRef | MustMod,
  /// The access neither references nor modifies the value stored in memory.
  NoModRef = 4,
  /// The access may reference the value stored in memory.
  Ref = NoModRef | MustRef,
  /// The access may modify the value stored in memory.
  Mod = NoModRef | MustMod,
  /// The access may reference and may modify the value stored in memory.
  ModRef = Ref | Mod,
};

inline ModRefInfo intersectModRef(const ModRefInfo MRI1,
    const ModRefInfo MRI2) {
  return ModRefInfo(static_cast<int>(MRI1) & static_cast<int>(MRI2));
}

ModRefInfo getModRefInfo(const ModRefInfo MRI) {
  ModRefInfo Result = ModRefInfo::ModRef;

  Result = intersectModRef(Result, MRI);
  return Result;
}

///////////////////////////////////////////////////////////////////////////////

(llvm commit: 37c74df)

Invocation:

clang-tidy -checks=-*,clang-analyzer-* test.cpp                               \
  --allow-enabling-analyzer-alpha-checkers                                    \
  -- -Xclang -analyzer-constraints -Xclang z3 		                      \
  -Xclang -analyzer-config 				                      \
  -Xclang aggressive-binary-operation-simplification=true

Stack Dump:

clang-tidy: /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:96: static const llvm::SMTExpr* clang::ento::SMTConv::fromBinOp(llvm::SMTSolverRef&, const llvm::SMTExpr* const&, clang::BinaryOperator::Opcode, const llvm::SMTExpr* const&, bool): Assertion `*Solver->getSort(LHS) == *Solver->getSort(RHS) && "AST's must have the same sort!"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: clang-tidy -checks=-*,clang-analyzer-* --allow-enabling-analyzer-alpha-checkers test.cpp -- -Xclang -analyzer-constraints -Xclang z3 -Xclang -analyzer-config -Xclang aggressive-binary-operation-simplification=true 
1.	<eof> parser at end of file
2.	While analyzing stack: 
	#0 Calling intersectModRef at line 35
	llvm/llvm-project#373 Calling getModRefInfo
3.	/root/test.cpp:28:10: Error evaluating statement
4.	/root/test.cpp:28:10: Error evaluating statement
 #&#8203;0 0x00007f70a1c66b43 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /workdir/llvm-project/llvm/lib/Support/Unix/Signals.inc:563:22
 #&#8203;1 0x00007f70a1c66bfa PrintStackTraceSignalHandler(void*) /workdir/llvm-project/llvm/lib/Support/Unix/Signals.inc:630:1
 #&#8203;2 0x00007f70a1c64bdd llvm::sys::RunSignalHandlers() /workdir/llvm-project/llvm/lib/Support/Signals.cpp:71:20
 #&#8203;3 0x00007f70a1c6658b SignalHandler(int) /workdir/llvm-project/llvm/lib/Support/Unix/Signals.inc:405:1
 #&#8203;4 0x00007f70a18a6730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
 #&#8203;5 0x00007f709b1817bb raise (/lib/x86_64-linux-gnu/libc.so.6+0x377bb)
 #&#8203;6 0x00007f709b16c535 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22535)
 #&#8203;7 0x00007f709b16c40f (/lib/x86_64-linux-gnu/libc.so.6+0x2240f)
 #&#8203;8 0x00007f709b17a102 (/lib/x86_64-linux-gnu/libc.so.6+0x30102)
 #&#8203;9 0x00007f70947b7588 clang::ento::SMTConv::fromBinOp(std::shared_ptr<llvm::SMTSolver>&, llvm::SMTExpr const* const&, clang::BinaryOperatorKind, llvm::SMTExpr const* const&, bool) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:95:5
#&#8203;10 0x00007f70947b86fe clang::ento::SMTConv::getBinExpr(std::shared_ptr<llvm::SMTSolver>&, clang::ASTContext&, llvm::SMTExpr const* const&, clang::QualType, clang::BinaryOperatorKind, llvm::SMTExpr const* const&, clang::QualType, clang::QualType*) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:377:3
#&#8203;11 0x00007f70947b8a2f clang::ento::SMTConv::getSymBinExpr(std::shared_ptr<llvm::SMTSolver>&, clang::ASTContext&, clang::ento::BinarySymExpr const*, bool*, clang::QualType*) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:396:24
#&#8203;12 0x00007f70947b8e67 clang::ento::SMTConv::getSymExpr(std::shared_ptr<llvm::SMTSolver>&, clang::ASTContext&, clang::ento::SymExpr const*, clang::QualType*, bool*) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:451:24
#&#8203;13 0x00007f70947b88f7 clang::ento::SMTConv::getSymBinExpr(std::shared_ptr<llvm::SMTSolver>&, clang::ASTContext&, clang::ento::BinarySymExpr const*, bool*, clang::QualType*) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:391:69
#&#8203;14 0x00007f70947b8e67 clang::ento::SMTConv::getSymExpr(std::shared_ptr<llvm::SMTSolver>&, clang::ASTContext&, clang::ento::SymExpr const*, clang::QualType*, bool*) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:451:24
#&#8203;15 0x00007f70947b8ef6 clang::ento::SMTConv::getExpr(std::shared_ptr<llvm::SMTSolver>&, clang::ASTContext&, clang::ento::SymExpr const*, clang::QualType*, bool*) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConv.h:474:3
#&#8203;16 0x00007f709496945c clang::ento::SMTConstraintManager::assumeSym(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::SymExpr const*, bool) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h:51:66
#&#8203;17 0x00007f709495cc63 clang::ento::SimpleConstraintManager::assumeAux(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:73:44
#&#8203;18 0x00007f709495c946 clang::ento::SimpleConstraintManager::assume(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:46:44
#&#8203;19 0x00007f709495c8c0 clang::ento::SimpleConstraintManager::assume(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::DefinedSVal, bool) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:41:57
#&#8203;20 0x00007f7092f348de clang::ento::ProgramState::assume(clang::ento::DefinedOrUnknownSVal, bool) const /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h:672:60
#&#8203;21 0x00007f70931a3284 (anonymous namespace)::ConstraintBasedEQEvaluator::operator()(llvm::APSInt const&) /workdir/llvm-project/clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:49:12
#&#8203;22 0x00007f70931a3ef3 bool __gnu_cxx::__ops::_Iter_pred<(anonymous namespace)::ConstraintBasedEQEvaluator>::operator()<llvm::APSInt*>(llvm::APSInt*) /usr/include/c++/8/bits/predefined_ops.h:283:33
#&#8203;23 0x00007f70931a3db8 llvm::APSInt* std::__find_if<llvm::APSInt*, __gnu_cxx::__ops::_Iter_pred<(anonymous namespace)::ConstraintBasedEQEvaluator> >(llvm::APSInt*, llvm::APSInt*, __gnu_cxx::__ops::_Iter_pred<(anonymous namespace)::ConstraintBasedEQEvaluator>, std::random_access_iterator_tag) /usr/include/c++/8/bits/stl_algo.h:120:4
#&#8203;24 0x00007f70931a3d23 llvm::APSInt* std::__find_if<llvm::APSInt*, __gnu_cxx::__ops::_Iter_pred<(anonymous namespace)::ConstraintBasedEQEvaluator> >(llvm::APSInt*, llvm::APSInt*, __gnu_cxx::__ops::_Iter_pred<(anonymous namespace)::ConstraintBasedEQEvaluator>) /usr/include/c++/8/bits/stl_algo.h:161:23
#&#8203;25 0x00007f70931a3bf1 llvm::APSInt* std::find_if<llvm::APSInt*, (anonymous namespace)::ConstraintBasedEQEvaluator>(llvm::APSInt*, llvm::APSInt*, (anonymous namespace)::ConstraintBasedEQEvaluator) /usr/include/c++/8/bits/stl_algo.h:3930:28
#&#8203;26 0x00007f70931a3b1f bool std::none_of<llvm::APSInt*, (anonymous namespace)::ConstraintBasedEQEvaluator>(llvm::APSInt*, llvm::APSInt*, (anonymous namespace)::ConstraintBasedEQEvaluator) /usr/include/c++/8/bits/stl_algo.h:526:71
#&#8203;27 0x00007f70931a3a01 bool std::any_of<llvm::APSInt*, (anonymous namespace)::ConstraintBasedEQEvaluator>(llvm::APSInt*, llvm::APSInt*, (anonymous namespace)::ConstraintBasedEQEvaluator) /usr/include/c++/8/bits/stl_algo.h:544:51
#&#8203;28 0x00007f70931a37d4 bool llvm::any_of<llvm::SmallVector<llvm::APSInt, 6u>&, (anonymous namespace)::ConstraintBasedEQEvaluator>(llvm::SmallVector<llvm::APSInt, 6u>&, (anonymous namespace)::ConstraintBasedEQEvaluator) /workdir/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1500:21
#&#8203;29 0x00007f70931a366c (anonymous namespace)::EnumCastOutOfRangeChecker::checkPreStmt(clang::CastExpr const*, clang::ento::CheckerContext&) const /workdir/llvm-project/clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:132:41
#&#8203;30 0x00007f70931a3c4d void clang::ento::check::PreStmt<clang::CastExpr>::_checkStmt<(anonymous namespace)::EnumCastOutOfRangeChecker>(void*, clang::Stmt const*, clang::ento::CheckerContext&) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/Checker.h:86:3
#&#8203;31 0x00007f7094820e4a clang::ento::CheckerFn<void (clang::Stmt const*, clang::ento::CheckerContext&)>::operator()(clang::Stmt const*, clang::ento::CheckerContext&) const /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:73:29
#&#8203;32 0x00007f709481aa94 (anonymous namespace)::CheckStmtContext::runChecker(clang::ento::CheckerFn<void (clang::Stmt const*, clang::ento::CheckerContext&)>, clang::ento::NodeBuilder&, clang::ento::ExplodedNode*) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:178:5
#&#8203;33 0x00007f709481d796 void expandGraphWithCheckers<(anonymous namespace)::CheckStmtContext>((anonymous namespace)::CheckStmtContext, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:138:5
#&#8203;34 0x00007f709481ab30 clang::ento::CheckerManager::runCheckersForStmt(bool, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::Stmt const*, clang::ento::ExprEngine&, bool) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp:192:26
#&#8203;35 0x00007f70948784a3 clang::ento::CheckerManager::runCheckersForPreStmt(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::Stmt const*, clang::ento::ExprEngine&) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h:253:23
#&#8203;36 0x00007f7094891c61 clang::ento::ExprEngine::VisitCast(clang::CastExpr const*, clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:305:44
#&#8203;37 0x00007f7094869bfa clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:1732:25
#&#8203;38 0x00007f7094865402 clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:792:15
#&#8203;39 0x00007f7094864784 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:637:18
#&#8203;40 0x00007f7094838628 clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:468:1
#&#8203;41 0x00007f7094837273 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (.localalias.0) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:192:7
#&#8203;42 0x00007f7094836f0d clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) /workdir/llvm-project/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:147:21
#&#8203;43 0x00007f70943cc0e5 clang::ento::ExprEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int) /workdir/llvm-project/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h:192:34
#&#8203;44 0x00007f7094356f38 (anonymous namespace)::AnalysisConsumer::RunPathSensitiveChecks(clang::Decl*, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*> >*) /workdir/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:703:22
#&#8203;45 0x00007f7094356d62 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet<clang::Decl const*, llvm::DenseMapInfo<clang::Decl const*> >*) /workdir/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:675:5
#&#8203;46 0x00007f7094355d03 (anonymous namespace)::AnalysisConsumer::HandleDeclsCallGraph(unsigned int) /workdir/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:467:31
#&#8203;47 0x00007f70943560fe (anonymous namespace)::AnalysisConsumer::runAnalysisOnTranslationUnit(clang::ASTContext&) /workdir/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:517:48
#&#8203;48 0x00007f70943562d3 (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) /workdir/llvm-project/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp:548:75
#&#8203;49 0x00007f709781cf1b clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) /workdir/llvm-project/clang/lib/Frontend/MultiplexConsumer.cpp:291:25
#&#8203;50 0x00007f70917cea9e clang::ParseAST(clang::Sema&, bool, bool) /workdir/llvm-project/clang/lib/Parse/ParseAST.cpp:178:14
#&#8203;51 0x00007f70977e2421 clang::ASTFrontendAction::ExecuteAction() /workdir/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1057:11
#&#8203;52 0x00007f70977e1d89 clang::FrontendAction::Execute() /workdir/llvm-project/clang/lib/Frontend/FrontendAction.cpp:954:38
#&#8203;53 0x00007f709776666a clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /workdir/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:984:42
#&#8203;54 0x00007f709fbf79b2 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) /workdir/llvm-project/clang/lib/Tooling/Tooling.cpp:410:46
#&#8203;55 0x00007f709f92a666 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) /workdir/llvm-project/clang-tools-extra/clang-tidy/ClangTidy.cpp:550:50
#&#8203;56 0x00007f709fbf7816 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) /workdir/llvm-project/clang/lib/Tooling/Tooling.cpp:385:31
#&#8203;57 0x00007f709fbf7654 clang::tooling::ToolInvocation::run() /workdir/llvm-project/clang/lib/Tooling/Tooling.cpp:370:23
#&#8203;58 0x00007f709fbf8ceb clang::tooling::ClangTool::run(clang::tooling::ToolAction*) /workdir/llvm-project/clang/lib/Tooling/Tooling.cpp:563:11
#&#8203;59 0x00007f709f92a9de clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, llvm::StringRef) /workdir/llvm-project/clang-tools-extra/clang-tidy/ClangTidy.cpp:572:28
#&#8203;60 0x00007f709f81e37e clang::tidy::clangTidyMain(int, char const**) /workdir/llvm-project/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:453:53
#&#8203;61 0x00005647eba01155 main /workdir/llvm-project/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp:20:47
#&#8203;62 0x00007f709b16e09b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409b)
#&#8203;63 0x00005647eba0107a _start (/workdir/llvm-project/build/llvm/bin/clang-tidy+0x107a)
test.sh: line 9: 54012 Aborted                 clang-tidy -checks=-*,clang-analyzer-* --allow-enabling-analyzer-alpha-checkers test.cpp -- -Xclang -analyzer-constraints -Xclang z3 -Xclang -analyzer-config -Xclang aggressive-binary-operation-simplification=true
@llvmbot
Copy link
Member Author

llvmbot commented Nov 19, 2020

assigned to @devincoughlin

@vabridgers
Copy link
Contributor

A workaround is to not use an underlying type (if that's possible).

Looks like SMTConv.h does not handle extraction of the underlying type for scoped enums.

Looking at ASTContext.cpp, there is a comment added from commit e65ab9e ...

+static const Type *getIntegerTypeForEnum(const EnumType *ET) {

  • // Incomplete enum types are not treated as integer types.
  • // FIXME: In C++, enum types are never integer types.
  • if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
  • return ET->getDecl()->getIntegerType().getTypePtr();
  • return NULL;
    +}

and SMTConv.h specifically only looks for Integral Or Enumeration types that are also Arithmetic - and a scoped enum is excluded as Arithmetic in Type.cpp, see ...

bool Type::isArithmeticType() const {
if (const auto *BT = dyn_cast(CanonicalType))
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::Float128 &&
BT->getKind() != BuiltinType::BFloat16;
if (const auto *ET = dyn_cast(CanonicalType))
// GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
// If a body isn't seen by the time we get here, return false.
//
// C++0x: Enumerations are not arithmetic types. For now, just return
// false for scoped enumerations since that will disable any
// unwanted implicit conversions.
return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
return isa(CanonicalType) || isExtIntType();
}

One approach in SMTConv.h is to check the LTy and RTy and "promote" the scoped enum to the LTy or RTy type. This seems to work. But I don't feel comfortable making this change at this time without first correcting the test infra to support non Z3 and Z3 usage when running LITs (per Balazs comments).

@steakhal
Copy link
Contributor

steakhal commented Jan 4, 2021

I think https://reviews.llvm.org/D85528 should resolve this.
However, we need a bit more time to evaluate the impact on the results.
The fix could not make into the latest release.
It would be awesome to find more considerably big projects using enum classes while casting them to the underlaying type.

Most of the projects we are testing on lack this property.
Let me know if you have some projects in mind!

Cheers.

@llvmbot
Copy link
Member Author

llvmbot commented Nov 27, 2021

changed the description

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
haoNoQ pushed a commit to swiftlang/llvm-project that referenced this issue Jul 19, 2022
We ignored the cast if the enum was scoped.
This is bad since there is no implicit conversion from the scoped enum to the corresponding underlying type.

The fix is basically: isIntegralOrEnumerationType() -> isIntegralOr**Unscoped**EnumerationType()

This materialized in crashes on analyzing the LLVM itself using the Z3 refutation.
Refutation synthesized the given Z3 Binary expression (`BO_And` of `unsigned char` aka. 8 bits
and an `int` 32 bits) with the wrong bitwidth in the end, which triggered an assert.

Now, we evaluate the cast according to the standard.

This bug could have been triggered using the Z3 CM according to
https://bugs.llvm.org/show_bug.cgi?id=44030

Fixes llvm#47570 llvm#43375

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D85528

(cherry picked from commit fd7efe3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:static analyzer confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

3 participants