<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/103493>103493</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPARC] Crash in `SparcAsmPrinter::printOperand()` when using function symbol as inline asm input
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
alexrp
</td>
</tr>
</table>
<pre>
```llvm
target datalayout = "E-m:e-i64:64-n32:64-S128"
target triple = "sparc64-unknown-linux-gnu"
define void @_start() {
Entry:
call void asm sideeffect "ba,a ${0}", "X"(ptr @start.posixCallMainAndExit)
unreachable
}
declare void @start.posixCallMainAndExit()
```
```console
❯ llc --version
LLVM (http://llvm.org/):
LLVM version 18.1.8
❯ llc -O0 reduced.ll
llc: /home/alexrp/Source/tests/llvm-project-18/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp:356: void {anonymous}::SparcAsmPrinter::printOperand(const llvm::MachineInstr*, int, llvm::raw_ostream&): Assertion `(TF == SparcMCExpr::VK_Sparc_LO || TF == SparcMCExpr::VK_Sparc_M44 || TF == SparcMCExpr::VK_Sparc_L44 || TF == SparcMCExpr::VK_Sparc_HM || TF == SparcMCExpr::VK_Sparc_TLS_GD_LO10 || TF == SparcMCExpr::VK_Sparc_TLS_LDM_LO10 || TF == SparcMCExpr::VK_Sparc_TLS_IE_LO10 ) && "Invalid target flags for small address operand"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: llc -O0 reduced.ll
1. Running pass 'Function Pass Manager' on module 'reduced.ll'.
2. Running pass 'Sparc Assembly Printer' on function '@_start'
#0 0x00007e801b55d8e2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/llvm/bin/../lib/libLLVM.so.18.1+0xd5d8e2)
#1 0x00007e801b55a8ff llvm::sys::RunSignalHandlers() (/opt/llvm/bin/../lib/libLLVM.so.18.1+0xd5a8ff)
#2 0x00007e801b55aa45 SignalHandler(int) Signals.cpp:0:0
#3 0x00007e801a042990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)
#4 0x00007e801a099a1b __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007e801a099a1b __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007e801a099a1b pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007e801a0428e6 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007e801a0268b7 abort ./stdlib/abort.c:81:7
#9 0x00007e801a0267db _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007e801a039206 (/lib/x86_64-linux-gnu/libc.so.6+0x39206)
#11 0x00007e801f7df834 (anonymous namespace)::SparcAsmPrinter::printOperand(llvm::MachineInstr const*, int, llvm::raw_ostream&) SparcAsmPrinter.cpp:0:0
#12 0x00007e801f7e0533 (anonymous namespace)::SparcAsmPrinter::PrintAsmOperand(llvm::MachineInstr const*, unsigned int, char const*, llvm::raw_ostream&) SparcAsmPrinter.cpp:0:0
#13 0x00007e801c2f4e19 llvm::AsmPrinter::emitInlineAsm(llvm::MachineInstr const*) const (/opt/llvm/bin/../lib/libLLVM.so.18.1+0x1af4e19)
#14 0x00007e801c2ee9be llvm::AsmPrinter::emitFunctionBody() (/opt/llvm/bin/../lib/libLLVM.so.18.1+0x1aee9be)
#15 0x00007e801c2f0fc9 llvm::AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (/opt/llvm/bin/../lib/libLLVM.so.18.1+0x1af0fc9)
#16 0x00007e801bb271f6 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#17 0x00007e801b74f4d1 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/llvm/bin/../lib/libLLVM.so.18.1+0xf4f4d1)
#18 0x00007e801b74f8e1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/llvm/bin/../lib/libLLVM.so.18.1+0xf4f8e1)
#19 0x00007e801b750207 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/llvm/bin/../lib/libLLVM.so.18.1+0xf50207)
#20 0x00005fe97c319896 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#21 0x00005fe97c30e117 main (/opt/llvm/bin/llc+0x12117)
#22 0x00007e801a028150 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#23 0x00007e801a028209 call_init ./csu/../csu/libc-start.c:128:20
#24 0x00007e801a028209 __libc_start_main ./csu/../csu/libc-start.c:347:5
#25 0x00005fe97c30ee15 _start (/opt/llvm/bin/llc+0x12e15)
```
Note: It also happens if the `X` is changed to `s`, but `X` is the use case I'm mainly concerned with.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WN1u4zoOfhrlRkggy_8XuUiTZk-x7baYDg7mzpBtOdGOLBuS3DZvv6DsJHYm0207OEXbOLL48SNFkZSYMWKnOF-i8AaFmxnr7L7RSyb5m25neVMeligi_a-ULzUiG0RWlukdt7hklkl2aDqLkb_BiNLbeY38FZ-LKED-Kgrmyqf9w7NHE0TpRN5q0Up-lDUt00UUzDv1UzWvai6F6t7mO9WdxPr_Ja-E4vilESVGAcmMZdoiQE8xim_6SbfK6gPyBxGMCyZlL8JMjY0oOa8qXlhQnDNE1wwjGqD4hqB4AwrpGl79cI9JazWocpoWbWPE25pJ-cCEWqny9k1YRNOjpk5pzoo9yyUfWMebKf1CMn3m_x5ocsI9LcIY6jRYNMo0J323FKUbtNpiKQs8n79wbUSj-pf3938_YESTvbUtuIduEd3Cwi4avXPf0pHX3OxBHnvJwlskV3U8Eqx52RW8XEjZz5CyQP4KI7rdNzVHdNuHFKLb56bTBYxYbqwZ1M9b3fyXF3buJcMIfIgc0e13FywgCAFy_FyZ-kkLZbleFC2Y4ocRKOzdGt8w1ahD3XQG3O-vkL-6EOsHW_jy2HLNVIloAo602Kl3rx9Ys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