<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149371>149371</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>
bi6c
</td>
</tr>
</table>
<pre>
Compiler Explorer: https://godbolt.org/z/oYcY9fdqj
- generated by fuzzer
```console
error: example.c:22:3: fixed input regs must be last on the x87 stack
error: example.c:22:3: implicitly popped regs must be last on the x87 stack
error: example.c:22:3: fixed input regs must be last on the x87 stack
error: example.c:22:3: implicitly popped regs must be last on the x87 stack
error: example.c:22:3: fixed input regs must be last on the x87 stack
error: example.c:22:3: implicitly popped regs must be last on the x87 stack
clang: /root/llvm-project/llvm/lib/Target/X86/X86FloatingPoint.cpp:992: 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 -fno-verbose-asm -c --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 <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 '@main'
#0 0x0000000003fbcfa8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fbcfa8)
#1 0x0000000003fba3d4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fba3d4)
#2 0x0000000003efeba8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007ff36c442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007ff36c4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007ff36c442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007ff36c4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007ff36c42871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007ff36c439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000029c1d5e (anonymous namespace)::FPS::adjustLiveRegs(unsigned int, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>) X86FloatingPoint.cpp:0:0
#10 0x00000000029c28c6 (anonymous namespace)::FPS::handleSpecialFP(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) X86FloatingPoint.cpp:0:0
#11 0x00000000029c4d47 (anonymous namespace)::FPS::processBasicBlock(llvm::MachineFunction&, llvm::MachineBasicBlock&) (.isra.0) X86FloatingPoint.cpp:0:0
#12 0x00000000029c7457 (anonymous namespace)::FPS::runOnMachineFunction(llvm::MachineFunction&) (.part.0) X86FloatingPoint.cpp:0:0
#13 0x00000000032c2873 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#14 0x00000000038eb15f llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x38eb15f)
#15 0x00000000038eb511 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x38eb511)
#16 0x00000000038ebd81 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x38ebd81)
#17 0x0000000004271c91 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, 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+0x4271c91)
#18 0x000000000496df03 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x496df03)
#19 0x00000000066638dc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66638dc)
#20 0x000000000496e308 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x496e308)
#21 0x0000000004c61c75 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c61c75)
#22 0x0000000004bde97e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bde97e)
#23 0x0000000004d55741 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d55741)
#24 0x0000000000d9e07f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9e07f)
#25 0x0000000000d94c5a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x00000000049d59c9 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 0x0000000003eff044 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3eff044)
#28 0x00000000049d5fdf 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 0x0000000004997eed clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4997eed)
#30 0x0000000004998f7e 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+0x4998f7e)
#31 0x00000000049a1bc5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49a1bc5)
#32 0x0000000000d9a52f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9a52f)
#33 0x0000000000c4ea64 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc4ea64)
#34 0x00007ff36c429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x00007ff36c429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000d94705 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd94705)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
Code:
```c
static __inline double mypow(double __x, double __y) {
register double __value, __exponent;
long __p = (long)__y;
if (__y == (double)__p) {
double __r = 1.0;
if (__p == 0)
return 1.0;
if (__p < 0) {
__p = -__p;
__x = 1.0 / __x;
}
while (1) {
if (__p & 1)
__r *= __x;
__p >>= 1;
if (__p == 0)
return __r;
__x *= __x;
}
}
__asm __volatile__("fmul %%st(1),%%st\n\t" /* y * log2(x) */
"fst %%st(1)\n\t"
"frndint\n\t" /* int(y * log2(x)) */
"fxch %%st(1)\n\t"
"fsub %%st(1),%%st\n\t" /* fract(y * log2(x)) */
"f2xm1\n\t" /* 2^(fract(y * log2(x))) - 1 */
: "=t"(__value), "=u"(__exponent)
: "R0"(__x), "1"(__y));
__value += 1.0;
__asm __volatile__("fscale" : "=t"(__value) : "0"(__value), "u"(__exponent));
return __value;
}
const double E1 = 2.71828182845904523536028747135;
double fact(double x) {
double corr;
corr = 1.0;
return corr * mypow(x / E1, x);
}
int main() {
double y, z;
y = fact(46.2);
z = mypow(46.2 / E1, 46.2);
return 0;
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWsty2zjWfhp4g5KKBO8LL2jZ-v90dSquODPVvWKBICihTQJsALSlPP0UQFK8WHbsjqZnMeOKYwmX73zn4Nx4wUqxHaf0GgQ3ILi9wq3eC3mds5Bc5aI4Xm9E3bCKSnh3aCohqQReCvdaNwp4KUBbgLY7UeSi0mshdwBtvwO0Fb-T35Oy-PMP4KQruKOcSqxpAfMjLNvv36kETmr-hU73jwiuREWBk1IphRVBD7huKromwEsRAl7qmdGSHWgBGW9aDSXdKVi3SsOcwgorDQWHek_hIY6g0pg8_hiP1U3FCNPVETaiaWhxEdT_sfwAS1JhvjP7AdpKITRA26p6qleNFH9QMnw1f1gO0PYbljtqRn-Lw-7_bSWwZnx3LxjXa9I0wEuTxNCCT4IVEEQ3mAt-rEWrQHRr3NZLt_cP3Qdc_NEq_St7ol_pTgEUt9xGhLGMBmgDrXS79DMme8bpDVaM3FSCPHbDTBvvFhKgxMhMlaJSM8EhCJ0Ho-Q30UDg3QLvFk7wAUpG6EY0RLRGYPwZq0eAEghQCFAIAUKGHLTTsGaqxprsAUIARbDErKLFGjjp_a936cMdVG1eMw0xzNsdlLQRUkMtlvHK9L7N10TUE-POTc6UaqkCaAsxN5YgVVtQe3REYrWHOSaPWmJCjYUaSRspCFWKFlCJVnbDZidWShBmY1-2HCoiWaMNX2sYWLS1OS3gpM4aOMm9FDuJa4jlrq0p16p3C9EYTqTPRCs6ZCK0tc6zw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