llvm / llvm-project

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

clang crashes on x86_64-linux-gnu: cannot pop empty stack #113692

Open bi6c opened 2 days ago

bi6c commented 2 days ago

Compiler Explorer: https://godbolt.org/z/5xWqKh1q3 (trace back to clang-3.6)

fatal error: error in backend: Cannot pop empty stack!
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-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 -fsanitize=undefined -fsanitize=address -O0 <source>
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module '<source>'.
4.  Running pass 'X86 FP Stackifier' on function '@add_sf'
 #0 0x000000000396cd78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x396cd78)
 #1 0x000000000396aee4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x396aee4)
 #2 0x00000000038bbd33 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bbd33)
 #3 0x000000000396292e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x396292e)
 #4 0x0000000000ce81db LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
 #5 0x00000000038c5d43 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38c5d43)
 #6 0x00000000038c5ea8 (/opt/compiler-explorer/clang-trunk/bin/clang+0x38c5ea8)
 #7 0x00000000023e45cf (anonymous namespace)::FPS::popStackAfter(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) X86FloatingPoint.cpp:0:0
 #8 0x00000000023ea764 (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&, llvm::MachineBasicBlock&) (.isra.0) X86FloatingPoint.cpp:0:0
 #9 0x00000000023eadfe (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) (.part.0) X86FloatingPoint.cpp:0:0
#10 0x00000000023eb68b (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) X86FloatingPoint.cpp:0:0
#11 0x0000000002d9405b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#12 0x00000000032e1a02 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e1a02)
#13 0x00000000032e1c91 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e1c91)
#14 0x00000000032e3636 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e3636)
#15 0x0000000003c0a2b5 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-trunk/bin/clang+0x3c0a2b5)
#16 0x00000000042b4174 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42b4174)
#17 0x00000000062adb8c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x62adb8c)
#18 0x00000000042b4895 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x42b4895)
#19 0x000000000457cdc1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x457cdc1)
#20 0x00000000044fc85b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x44fc85b)
#21 0x0000000004661333 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4661333)
#22 0x0000000000cea38c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xcea38c)
#23 0x0000000000ce2ded ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x00000000042fcea9 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
#25 0x00000000038bbc33 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bbc33)
#26 0x00000000042fd0c9 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
#27 0x00000000042c427d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x42c427d)
#28 0x00000000042c527d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x42c527d)
#29 0x00000000042ceccc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42ceccc)
#30 0x0000000000ce70e1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xce70e1)
#31 0x0000000000bb9a54 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xbb9a54)
#32 0x000072f306e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#33 0x000072f306e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#34 0x0000000000ce288e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xce288e)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70

Code:

#include <stdio.h>

float add_sf (float *p, float *q) {
    float f1 = *p;
    float f2 = *q;
    __asm__(" " : "+f" (f1), "+f" (f2));
    printf("float: %f + %f = %f\n", f1, f2, f1 + f2);
    return f1 + f2;
}

int main() {
    float num1 = 12.345;
    float num2 = 67.890;

    add_sf(&num1, &num2);

    return 0;
}
llvmbot commented 2 days ago

@llvm/issue-subscribers-backend-x86

Author: None (bi6c)

Compiler Explorer: https://godbolt.org/z/5xWqKh1q3 ```console fatal error: error in backend: Cannot pop empty stack! 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-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 -fsanitize=undefined -fsanitize=address -O0 <source> 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '<source>'. 4. Running pass 'X86 FP Stackifier' on function '@add_sf' #0 0x000000000396cd78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x396cd78) #1 0x000000000396aee4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x396aee4) #2 0x00000000038bbd33 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bbd33) #3 0x000000000396292e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x396292e) #4 0x0000000000ce81db LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0 #5 0x00000000038c5d43 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38c5d43) #6 0x00000000038c5ea8 (/opt/compiler-explorer/clang-trunk/bin/clang+0x38c5ea8) #7 0x00000000023e45cf (anonymous namespace)::FPS::popStackAfter(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) X86FloatingPoint.cpp:0:0 #8 0x00000000023ea764 (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&, llvm::MachineBasicBlock&) (.isra.0) X86FloatingPoint.cpp:0:0 #9 0x00000000023eadfe (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) (.part.0) X86FloatingPoint.cpp:0:0 #10 0x00000000023eb68b (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) X86FloatingPoint.cpp:0:0 #11 0x0000000002d9405b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #12 0x00000000032e1a02 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e1a02) #13 0x00000000032e1c91 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e1c91) #14 0x00000000032e3636 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e3636) #15 0x0000000003c0a2b5 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-trunk/bin/clang+0x3c0a2b5) #16 0x00000000042b4174 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42b4174) #17 0x00000000062adb8c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x62adb8c) #18 0x00000000042b4895 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x42b4895) #19 0x000000000457cdc1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x457cdc1) #20 0x00000000044fc85b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x44fc85b) #21 0x0000000004661333 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4661333) #22 0x0000000000cea38c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xcea38c) #23 0x0000000000ce2ded ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #24 0x00000000042fcea9 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 #25 0x00000000038bbc33 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bbc33) #26 0x00000000042fd0c9 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 #27 0x00000000042c427d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x42c427d) #28 0x00000000042c527d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x42c527d) #29 0x00000000042ceccc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42ceccc) #30 0x0000000000ce70e1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xce70e1) #31 0x0000000000bb9a54 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xbb9a54) #32 0x000072f306e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #33 0x000072f306e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #34 0x0000000000ce288e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xce288e) clang: error: clang frontend command failed with exit code 70 (use -v to see invocation) Compiler returned: 70 ``` Code: ```c #include <stdio.h> float add_sf (float *p, float *q) { float f1 = *p; float f2 = *q; __asm__(" " : "+f" (f1), "+f" (f2)); printf("float: %f + %f = %f\n", f1, f2, f1 + f2); return f1 + f2; } int main() { float num1 = 12.345; float num2 = 67.890; add_sf(&num1, &num2); return 0; } ```