[clang] Regression: crash compiling dynamic_cast with final class and optimisation level higher than 0 (original) (raw)
Since clang 19, the following minimal code will crash the compiler when compiled with an optimisation level -O1 or higher:
class base { virtual void fn() = 0; };
class test final : base { virtual void fn() { } };
test* new_test() { return new test(); }
test* cast(base* b) {
return dynamic_cast<test*>(b); // crash here!
}
On my PC, I get the error "fatal error: error in backend: Broken module found, compilation aborted!"
See demo here: https://godbolt.org/z/edsE14hqh
Remove the 'final' on class test and the code will compile again.
Full error:
PHINode should have one entry for each predecessor of its parent basic block! %2 = phi ptr [ poison, <null operand!> ], [ null, %dynamic_cast.null ], !dbg !59 fatal error: error in backend: Broken module found, compilation aborted!
Backtrace:
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -O1 1. parser at end of file 2. Optimizer 3. Running pass "verify" on module "" #0 0x0000000003f185e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f185e8) #1 0x0000000003f16274 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f16274) #2 0x0000000003e5b306 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e5b306) #3 0x0000000003f0d99e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f0d99e) #4 0x0000000000d9fda0 LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0 #5 0x0000000003e65fe3 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e65fe3) #6 0x0000000003e66148 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e66148) #7 0x00000000038efa78 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38efa78) #8 0x00000000041bd52e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManagerllvm::Module>::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41bd52e) #9 0x00000000038b9df0 llvm::PassManager<llvm::Module, llvm::AnalysisManagerllvm::Module>::run(llvm::Module&, llvm::AnalysisManagerllvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38b9df0) #10 0x00000000041cbe32 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream>&, std::unique_ptr<llvm::ToolOutputFile, std::default_deletellvm::ToolOutputFile>&, clang::BackendConsumer*) BackendUtil.cpp:0:0 #11 0x00000000041cf57b clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtrllvm::vfs::FileSystem, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41cf57b) #12 0x00000000048b7af0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48b7af0) #13 0x0000000006579a1c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6579a1c) #14 0x00000000048b7ed8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48b7ed8) #15 0x0000000004bab3c5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bab3c5) #16 0x0000000004b2a0ee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b2a0ee) #17 0x0000000004c9a9fe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c9a9fe) #18 0x0000000000da245f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda245f) #19 0x0000000000d9946a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #20 0x000000000491e759 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optionalllvm::StringRef>, std::__cxx11::basic_string<char, std::char_traits, std::allocator>, bool) const::'lambda'()>(long) Job.cpp:0:0 #21 0x0000000003e5b244 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e5b244) #22 0x000000000491ed6f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optionalllvm::StringRef>, std::__cxx11::basic_string<char, std::char_traits, std::allocator>, bool) const (.part.0) Job.cpp:0:0 #23 0x00000000048e11cd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48e11cd) #24 0x00000000048e225e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48e225e) #25 0x00000000048ea0b5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48ea0b5) #26 0x0000000000d9f1a8 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9f1a8) #27 0x0000000000c24bd4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc24bd4) #28 0x000070ea18a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #29 0x000070ea18a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #30 0x0000000000d98f15 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd98f15) clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation) Compiler returned: 70