<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117882>117882</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`llvm.experimental.patchpoint` followed by a call causes assertion error in x86 backend
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vchuravy
</td>
</tr>
</table>
<pre>
The following small reproducer causes an assertion error: https://godbolt.org/z/Ej57Gsvdb
```
; ModuleID = 'bugpoint-reduced-simplified.bc'
target triple = "x86_64-pc-linux-gnu"
define void @julia_readcb_specialized_17() {
top:
call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 1, i32 0, ptr null, i32 0)
call void @jlsys_notify_4()
ret void
}
declare void @llvm.experimental.patchpoint.void(i64, i32, ptr, i32, ...)
declare void @jlsys_notify_4()
```
```
llc: /root/llvm-project/llvm/lib/CodeGen/StackMaps.cpp:202: unsigned int getDwarfRegNum(unsigned int, const llvm::TargetRegisterInfo*): Assertion `RegNum >= 0 && isUInt<16>(RegNum) && "Invalid Dwarf register number."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel <source>
1. Running pass 'Function Pass Manager' on module '<source>'.
2. Running pass 'X86 Assembly Printer' on function '@julia_readcb_specialized_17'
#0 0x0000000003c1d988 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3c1d988)
#1 0x0000000003c1b37c SignalHandler(int) Signals.cpp:0:0
#2 0x00007caf04842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007caf048969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x00007caf04842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x00007caf048287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x00007caf0482871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#7 0x00007caf04839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#8 0x0000000002e60fae getDwarfRegNum(unsigned int, llvm::TargetRegisterInfo const*) StackMaps.cpp:0:0
#9 0x0000000002e62b70 llvm::StackMaps::parseRegisterLiveOutMask(unsigned int const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2e62b70)
#10 0x0000000002e65034 llvm::StackMaps::parseOperand(llvm::MachineOperand const*, llvm::MachineOperand const*, llvm::SmallVector<llvm::StackMaps::Location, 8u>&, llvm::SmallVector<llvm::StackMaps::LiveOutReg, 8u>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2e65034)
#11 0x0000000002e66461 llvm::StackMaps::recordStackMapOpers(llvm::MCSymbol const&, llvm::MachineInstr const&, unsigned long, llvm::MachineOperand const*, llvm::MachineOperand const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2e66461)
#12 0x0000000002e67196 llvm::StackMaps::recordPatchPoint(llvm::MCSymbol const&, llvm::MachineInstr const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2e67196)
#13 0x0000000001eb06e8 llvm::X86AsmPrinter::LowerPATCHPOINT(llvm::MachineInstr const&, (anonymous namespace)::X86MCInstLower&) X86MCInstLower.cpp:0:0
#14 0x0000000001eb173d llvm::X86AsmPrinter::emitInstruction(llvm::MachineInstr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1eb173d)
#15 0x00000000028b6871 llvm::AsmPrinter::emitFunctionBody() (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x28b6871)
#16 0x0000000001ea320b llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x1ea320b)
#17 0x0000000002b81649 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#18 0x0000000003186770 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3186770)
#19 0x0000000003186b21 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x3186b21)
#20 0x00000000031873d7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x31873d7)
#21 0x000000000086ebc8 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#22 0x000000000075fbce main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x75fbce)
#23 0x00007caf04829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#24 0x00007caf04829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#25 0x000000000086550e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x86550e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
I might be using patchpoints wrong, but I am not seeing any obvious mistakes
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8WF1v2zjT_TXMDWGDomR9XPjCdepugGYbNH2LvTMoaiyzoUiBpJJ4f_0L6iOyXDdpusZTpEhEkWfOHM4MqWHWilIBLNHiA1pcX7HG7bVZPvJ9Y9jj4SrXxWH5bQ94p6XUT0KV2FZMSmygNrpoOBjMWWPBYqYwsxaME1phMEYbFK7w3rnaonCF6AbRTamLXEs316ZEdPMvopuPPxbJJ_tY5Iis_E9M-h-yQuEHfKuLRsLNNUbhNUY0yZuy1kK5mQFvvJhZUdVS7AQU85wjmiCycsyU4LAzopbQL6TPabyNo1nNZ1Ko5nlWqgZR2hktYCcU4EctCowi8qORgm0NsILnW1sDF0yKf6HYBgmiKaIZRskHb0fX3jGywph7Sbr1NBVxhOgai5D6X7UzR0_z-bwF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