llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.14k stars 11.11k forks source link

__asm__ causes crash with -fms-hotpatch #77179

Open tycho opened 6 months ago

tycho commented 6 months ago

Found another -fms-hotpatch problem:

void test(void) {
    __asm__ __volatile__("nop" ::: "memory");
}

When compiled at -O1 or higher, with -fms-hotpatch, it crashes the compiler (godbolt link):

PATCHABLE_OP 2, 1, &nop, 25, 12, 12, 12, !14, implicit-def dead early-clobber $df, implicit-def early-clobber $fpsw, implicit-def dead early-clobber $eflags, debug-location !13; example.cpp:2:2
unknown operand type
UNREACHABLE executed at /root/llvm-project/llvm/lib/Target/X86/X86MCInstLower.cpp:334!
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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O1 -fno-optimize-sibling-calls -fms-hotpatch <source>
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module '<source>'.
4.  Running pass 'X86 Assembly Printer' on function '@_Z4testv'
 #0 0x00000000037de8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37de8b8)
 #1 0x00000000037dc59c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37dc59c)
 #2 0x0000000003724de8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2e03c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f2e03c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f2e03c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f2e03c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000000000373007a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x373007a)
 #8 0x00000000022e758c (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x22e758c)
 #9 0x00000000022e7b2a llvm::X86AsmPrinter::LowerPATCHABLE_OP(llvm::MachineInstr const&, (anonymous namespace)::X86MCInstLower&) X86MCInstLower.cpp:0:0
#10 0x00000000022ea060 llvm::X86AsmPrinter::emitInstruction(llvm::MachineInstr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x22ea060)
#11 0x00000000046698af llvm::AsmPrinter::emitFunctionBody() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46698af)
#12 0x00000000022dc4c1 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x22dc4c1)
#13 0x0000000002bd0901 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#14 0x00000000031901e9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x31901e9)
#15 0x0000000003190421 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3190421)
#16 0x0000000003190c62 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3190c62)
#17 0x0000000003a57296 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#18 0x0000000003a57621 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a57621)
#19 0x000000000405e98c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x405e98c)
#20 0x0000000005fd6149 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5fd6149)
#21 0x000000000405dd28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x405dd28)
#22 0x00000000042cae49 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42cae49)
#23 0x0000000004249f7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4249f7e)
#24 0x00000000043aa64e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43aa64e)
#25 0x0000000000c05476 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc05476)
#26 0x0000000000bfcd3a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x000000000409ee69 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#28 0x0000000003725294 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3725294)
#29 0x000000000409f45f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#30 0x00000000040675c5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40675c5)
#31 0x000000000406802d 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+++0x406802d)
#32 0x000000000406ff25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x406ff25)
#33 0x0000000000c028fc clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc028fc)
#34 0x0000000000afb5f1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xafb5f1)
#35 0x00007f2e03c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#36 0x00007f2e03c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#37 0x0000000000bfc81e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbfc81e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 6 months ago

@llvm/issue-subscribers-backend-x86

Author: Steven Noonan (tycho)

Found another `-fms-hotpatch` problem: ```c++ void test(void) { __asm__ __volatile__("nop" ::: "memory"); } ``` When compiled at `-O1` or higher, with `-fms-hotpatch`, it crashes the compiler ([godbolt link](https://gcc.godbolt.org/z/fE1nK77e7)): ``` PATCHABLE_OP 2, 1, &nop, 25, 12, 12, 12, !14, implicit-def dead early-clobber $df, implicit-def early-clobber $fpsw, implicit-def dead early-clobber $eflags, debug-location !13; example.cpp:2:2 unknown operand type UNREACHABLE executed at /root/llvm-project/llvm/lib/Target/X86/X86MCInstLower.cpp:334! 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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O1 -fno-optimize-sibling-calls -fms-hotpatch <source> 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '<source>'. 4. Running pass 'X86 Assembly Printer' on function '@_Z4testv' #0 0x00000000037de8b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37de8b8) #1 0x00000000037dc59c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37dc59c) #2 0x0000000003724de8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007f2e03c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007f2e03c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007f2e03c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007f2e03c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x000000000373007a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x373007a) #8 0x00000000022e758c (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x22e758c) #9 0x00000000022e7b2a llvm::X86AsmPrinter::LowerPATCHABLE_OP(llvm::MachineInstr const&, (anonymous namespace)::X86MCInstLower&) X86MCInstLower.cpp:0:0 #10 0x00000000022ea060 llvm::X86AsmPrinter::emitInstruction(llvm::MachineInstr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x22ea060) #11 0x00000000046698af llvm::AsmPrinter::emitFunctionBody() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46698af) #12 0x00000000022dc4c1 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x22dc4c1) #13 0x0000000002bd0901 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #14 0x00000000031901e9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x31901e9) #15 0x0000000003190421 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3190421) #16 0x0000000003190c62 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3190c62) #17 0x0000000003a57296 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0 #18 0x0000000003a57621 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a57621) #19 0x000000000405e98c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x405e98c) #20 0x0000000005fd6149 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5fd6149) #21 0x000000000405dd28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x405dd28) #22 0x00000000042cae49 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42cae49) #23 0x0000000004249f7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4249f7e) #24 0x00000000043aa64e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43aa64e) #25 0x0000000000c05476 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc05476) #26 0x0000000000bfcd3a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #27 0x000000000409ee69 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0 #28 0x0000000003725294 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3725294) #29 0x000000000409f45f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0 #30 0x00000000040675c5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40675c5) #31 0x000000000406802d 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+++0x406802d) #32 0x000000000406ff25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x406ff25) #33 0x0000000000c028fc clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc028fc) #34 0x0000000000afb5f1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xafb5f1) #35 0x00007f2e03c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #36 0x00007f2e03c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #37 0x0000000000bfc81e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbfc81e) clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ````