Description
This code:
target triple = "wasm32-unknown-unknown"
declare void @llvm.trap() cold noreturn nounwind
declare i32 @return_i32()
declare void @take_i32(i32)
define void @assert_fail() {
%a = call i32 @return_i32()
call void @llvm.trap()
call void @take_i32(i32 %a)
ret void
}
causes an assertion failure:
llc: /root/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp:168: void query(const llvm::MachineInstr&, bool&, bool&, bool&, bool&): Assertion `!MI.isTerminator()' 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 'WebAssembly Register Stackify' on function '@assert_fail'
#0 0x00000000034145c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x34145c8)
#1 0x0000000003411cfc SignalHandler(int) Signals.cpp:0:0
#2 0x00007f9f6cda2420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x00007f9f6c86500b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#4 0x00007f9f6c844859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#5 0x00007f9f6c844729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#6 0x00007f9f6c855fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#7 0x0000000001ac853e query(llvm::MachineInstr const&, bool&, bool&, bool&, bool&) WebAssemblyRegStackify.cpp:0:0
#8 0x0000000001ac924f isSafeToMove(llvm::MachineOperand const*, llvm::MachineOperand const*, llvm::MachineInstr const*, llvm::WebAssemblyFunctionInfo const&, llvm::MachineRegisterInfo const&) (.isra.0) WebAssemblyRegStackify.cpp:0:0
#9 0x0000000001acc728 (anonymous namespace)::WebAssemblyRegStackify::runOnMachineFunction(llvm::MachineFunction&) WebAssemblyRegStackify.cpp:0:0
#10 0x00000000026f1e21 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x0000000002c70009 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2c70009)
#12 0x0000000002c70241 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2c70241)
#13 0x0000000002c70a62 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x2c70a62)
#14 0x0000000000760e52 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
#15 0x000000000069ec46 main (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x69ec46)
#16 0x00007f9f6c846083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#17 0x00000000007577ee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/llc+0x7577ee)
Program terminated with signal: SIGSEGV
Compiler returned: 139
It seems like this line in WebAssemblyRegStackify::runOnMachineFunction calls isSafeToMove()
which calls query() in two places
which has the line assert(!MI.isTerminator());
which trips over the fact that unreachable (what @llvm.trap()
is compiled to) is defined as a terminator