<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/69070>69070</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang: Assertion `StackTop == (unsigned)llvm::popcount(Mask) && "Live count mismatch"' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          connglli
      </td>
    </tr>
</table>

<pre>
    Compiler explorer: https://godbolt.org/z/Pve8WW1v8.

The following program `small.c` triggers a crash in clang-18:

``` sh
% cat small.c
void foo(double d)
{
  __asm__ ("" : "=u" (d));__asm__ ("" : "=u" (d));
}


% clang -O0 small.c
<source>:3:12: error: output regs must be last on the x87 stack
    3 |   __asm__ ("" : "=u" (d));__asm__ ("" : "=u" (d));
      | ^
<source>:3:36: error: output regs must be last on the x87 stack
    3 |   __asm__ ("" : "=u" (d));__asm__ ("" : "=u" (d));
      | ^
clang: /root/llvm-project/llvm/lib/Target/X86/X86FloatingPoint.cpp:976: void {anonymous}::FPS::adjustLiveRegs(unsigned int, llvm::MachineBasicBlock::iterator): Assertion `StackTop == (unsigned)llvm::popcount(Mask) && "Live count mismatch"' failed.
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-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -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 '@foo'
 #0 0x000000000372dd18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x372dd18)
 #1 0x000000000372b9dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x372b9dc)
 #2 0x00000000036742f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f86961b5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f8695c7800b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f8695c57859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f8695c57729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f8695c68fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00000000022d94be (anonymous namespace)::FPS::adjustLiveRegs(unsigned int, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>) X86FloatingPoint.cpp:0:0
 #9 0x00000000022dbe0b (anonymous namespace)::FPS::handleSpecialFP(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) X86FloatingPoint.cpp:0:0
#10 0x00000000022dc540 (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&, llvm::MachineBasicBlock&) (.isra.0) X86FloatingPoint.cpp:0:0
#11 0x00000000022deac4 (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) (.part.0) X86FloatingPoint.cpp:0:0
#12 0x0000000002b02d21 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#13 0x00000000030b13f9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30b13f9)
#14 0x00000000030b1631 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30b1631)
#15 0x00000000030b1e52 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x30b1e52)
#16 0x00000000039a2382 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) BackendUtil.cpp:0:0
#17 0x00000000039a2829 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>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39a2829)
#18 0x00000000049990bf clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49990bf)
#19 0x0000000005e9b6f9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5e9b6f9)
#20 0x00000000049982a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49982a8)
#21 0x00000000041fc4f9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x41fc4f9)
#22 0x000000000417d9ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x417d9ce)
#23 0x00000000042db54e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42db54e)
#24 0x0000000000bef0e6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbef0e6)
#25 0x0000000000be69aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x0000000003fd9c19 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
#27 0x00000000036747a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x36747a4)
#28 0x0000000003fda20f 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
#29 0x0000000003fa23d5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fa23d5)
#30 0x0000000003fa2e3d 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+0x3fa2e3d)
#31 0x0000000003faad65 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3faad65)
#32 0x0000000000bec58c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbec58c)
#33 0x0000000000ae6751 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xae6751)
#34 0x00007f8695c59083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#35 0x0000000000be648e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbe648e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```

Clang version:

```
clang version 18.0.0 (https://github.com/llvm/llvm-project.git f2b79ed9c6c858426b15a0374103ab901b5b2ef3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk/bin
```
</pre>
<img width="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