<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149969>149969</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISCV] Crash when ir-outliner is run on functions with interrupt attribute
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
svs-quic
</td>
</tr>
</table>
<pre>
Consider the IR:
https://godbolt.org/z/czqe7ja33
```
define void @bar() "interrupt"="machine" {
%1 = tail call i32 asm sideeffect "li $0, $1", "=r,i"(i32 10) nounwind
%3 = and i32 %1, 31
%4 = add nsw i32 %3, 6
%5 = urem i32 %4, 24
%6 = shl nuw nsw i32 1, %5
tail call void @foo(i32 noundef %6) nounwind
ret void
}
declare void @foo(i32 noundef) #2
define void @baz() "interrupt"="machine" {
%1 = tail call i32 asm sideeffect "li $0, $1", "=r,i"(i32 10) nounwind
%3 = and i32 %1, 31
%4 = add nsw i32 %3, 6
%5 = urem i32 %4, 24
%6 = shl nuw nsw i32 1, %5
tail call void @foo(i32 noundef %6) nounwind
ret void
}
```
The IR Outliner when run on this IR produces:
```
define void @bar() #0 {
%1 = tail call i32 asm sideeffect "li $0, $1", "=r,i"(i32 10) #2
call void @outlined_ir_func_0(i32 %1)
ret void
}
declare void @foo(i32 noundef)
define void @baz() #0 {
%1 = tail call i32 asm sideeffect "li $0, $1", "=r,i"(i32 10) #2
call void @outlined_ir_func_0(i32 %1)
ret void
}
define internal void @outlined_ir_func_0(i32 %0) #1 {
newFuncRoot:
br label %_to_outline
_to_outline:
%1 = and i32 %0, 31
%2 = add nsw i32 %1, 6
%3 = urem i32 %2, 24
%4 = shl nuw nsw i32 1, %3
tail call void @foo(i32 noundef %4) #2
br label %_after_outline.exitStub
_after_outline.exitStub:
ret void
}
attributes #0 = { "interrupt"="machine" }
attributes #1 = { minsize optsize "interrupt"="machine" }
attributes #2 = { nounwind }
```
When we trying to run the following IR it crashes with the following message:
```
LLVM ERROR: Functions with the interrupt attribute cannot have arguments!
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-trunk/bin/llc -o /app/output.s -x86-asm-syntax=intel -mtriple riscv32 <source>
1. Running pass 'Function Pass Manager' on module '<source>'.
2. Running pass 'RISC-V DAG->DAG Pattern Instruction Selection' on function '@outlined_ir_func_0'
#0 0x0000000003bac828 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/llc+0x3bac828)
#1 0x0000000003ba99f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x00007aa330242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x00007aa3302969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x00007aa330242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x00007aa3302287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x0000000000794a80 llvm::UniqueStringSaver::save(llvm::Twine const&) (.cold) StringSaver.cpp:0:0
#7 0x0000000003b00648 (/opt/compiler-explorer/clang-trunk/bin/llc+0x3b00648)
#8 0x0000000001b89fbc llvm::RISCVTargetLowering::LowerFormalArguments(llvm::SDValue, unsigned int, bool, llvm::SmallVectorImpl<llvm::ISD::InputArg> const&, llvm::SDLoc const&, llvm::SelectionDAG&, llvm::SmallVectorImpl<llvm::SDValue>&) const (/opt/compiler-explorer/clang-trunk/bin/llc+0x1b89fbc)
#9 0x00000000038dc1ca llvm::SelectionDAGISel::LowerArguments(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x38dc1ca)
#10 0x000000000395ff65 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x395ff65)
#11 0x00000000039609b6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x39609b6)
#12 0x000000000394d431 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x394d431)
#13 0x0000000002c0ca1d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x2c0ca1d)
#14 0x000000000318fce2 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x318fce2)
#15 0x000000000318ff71 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x318ff71)
#16 0x00000000031918b9 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/llc+0x31918b9)
#17 0x00000000008d93a9 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#18 0x00000000007aab3e main (/opt/compiler-explorer/clang-trunk/bin/llc+0x7aab3e)
#19 0x00007aa330229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#20 0x00007aa330229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#21 0x00000000008d0c35 _start (/opt/compiler-explorer/clang-trunk/bin/llc+0x8d0c35)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
https://godbolt.org/z/drvWcKxYM
It looks like the IR Outliner is copying over the attributes from the original functions to the outlined one leading to this error. We could probably mark the function as `nooutline` but I don't think the outliner is doing anything incorrect here. Should we not be propogating the interrupt attribute to the outlined function?
It seems ARM is okay with this: https://godbolt.org/z/fv1GGc3oG
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWV1v4joa_jXujQVy7BDIBRdMKd1qW52qzPZor5DjOOBTx87YDrTz61d2EkhoO99nVivtqCOCP573eT_j11BrxVZxPgeTD2CyvKC122kzt3s7-lQLdpHp_GV-qZUVOTfQ7Ti8eQB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