Skip to content
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

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

Open
bi6c opened this issue Oct 25, 2024 · 1 comment
Open

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

bi6c opened this issue Oct 25, 2024 · 1 comment
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@bi6c
Copy link

bi6c commented Oct 25, 2024

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;
}
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Oct 25, 2024
@EugeneZelenko EugeneZelenko added backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Oct 25, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 25, 2024

@llvm/issue-subscribers-backend-x86

Author: None (bi6c)

Compiler Explorer: https://godbolt.org/z/5xWqKh1q3
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 &lt;source&gt;
1.	&lt;eof&gt; parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '&lt;source&gt;'.
4.	Running pass 'X86 FP Stackifier' on function '@<!-- -->add_sf'
 #<!-- -->0 0x000000000396cd78 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, 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&amp;, 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&lt;llvm::MachineInstr, false&gt;&amp;) X86FloatingPoint.cpp:0:0
 #<!-- -->8 0x00000000023ea764 (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&amp;, llvm::MachineBasicBlock&amp;) (.isra.0) X86FloatingPoint.cpp:0:0
 #<!-- -->9 0x00000000023eadfe (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&amp;) (.part.0) X86FloatingPoint.cpp:0:0
#<!-- -->10 0x00000000023eb68b (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&amp;) X86FloatingPoint.cpp:0:0
#<!-- -->11 0x0000000002d9405b llvm::MachineFunctionPass::runOnFunction(llvm::Function&amp;) (.part.0) MachineFunctionPass.cpp:0:0
#<!-- -->12 0x00000000032e1a02 llvm::FPPassManager::runOnFunction(llvm::Function&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e1a02)
#<!-- -->13 0x00000000032e1c91 llvm::FPPassManager::runOnModule(llvm::Module&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e1c91)
#<!-- -->14 0x00000000032e3636 llvm::legacy::PassManagerImpl::run(llvm::Module&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+0x32e3636)
#<!-- -->15 0x0000000003c0a2b5 clang::EmitBackendOutput(clang::DiagnosticsEngine&amp;, clang::HeaderSearchOptions const&amp;, clang::CodeGenOptions const&amp;, clang::TargetOptions const&amp;, clang::LangOptions const&amp;, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::FileSystem&gt;, std::unique_ptr&lt;llvm::raw_pwrite_stream, std::default_delete&lt;llvm::raw_pwrite_stream&gt;&gt;, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3c0a2b5)
#<!-- -->16 0x00000000042b4174 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42b4174)
#<!-- -->17 0x00000000062adb8c clang::ParseAST(clang::Sema&amp;, 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&amp;) (/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&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xcea38c)
#<!-- -->23 0x0000000000ce2ded ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->24 0x00000000042fcea9 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->25 0x00000000038bbc33 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bbc33)
#<!-- -->26 0x00000000042fd0c9 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->27 0x00000000042c427d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x42c427d)
#<!-- -->28 0x00000000042c527d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x42c527d)
#<!-- -->29 0x00000000042ceccc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42ceccc)
#<!-- -->30 0x0000000000ce70e1 clang_main(int, char**, llvm::ToolContext const&amp;) (/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 &lt;stdio.h&gt;

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(&amp;num1, &amp;num2);

    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants