Skip to content

Commit 5c92f23

Browse files
authored
[WebAssembly] Fix MIR printing of reference types (#113028)
When printing a memory operand in MIR, this line https://github.com/llvm/llvm-project/blob/d37bc32a65651e647148236ffb9728ea2e77eac3/llvm/lib/CodeGen/MachineOperand.cpp#L1247 calls this https://github.com/llvm/llvm-project/blob/d37bc32a65651e647148236ffb9728ea2e77eac3/llvm/include/llvm/Support/Alignment.h#L238 which assumes `Rhs` (the size in this case) is positive. But Wasm reference types' size is set to 0: https://github.com/llvm/llvm-project/blob/d37bc32a65651e647148236ffb9728ea2e77eac3/llvm/include/llvm/CodeGen/ValueTypes.td#L326-L328 `getSize() > 0` condition was added with the Wasm reference types support in 46667a1, and it looks it was removed in #84751. This revives the condition so that Wasm reference types will not crash the MIR printer.
1 parent 71792dc commit 5c92f23

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/lib/CodeGen/MachineOperand.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,8 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
12441244
}
12451245
MachineOperand::printOperandOffset(OS, getOffset());
12461246
if (!getSize().hasValue() ||
1247-
getAlign() != getSize().getValue().getKnownMinValue())
1247+
(!getSize().isZero() &&
1248+
getAlign() != getSize().getValue().getKnownMinValue()))
12481249
OS << ", align " << getAlign().value();
12491250
if (getAlign() != getBaseAlign())
12501251
OS << ", basealign " << getBaseAlign().value();

llvm/test/CodeGen/WebAssembly/externref-globalget.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types | FileCheck %s
2+
; Test for MIR printing of reference types in other address spaces. This should
3+
; not error out.
4+
; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false -mattr=+reference-types -print-after=finalize-isel | FileCheck %s
25

36
%externref = type ptr addrspace(10) ;; addrspace 10 is nonintegral
47

0 commit comments

Comments
 (0)