Skip to content

Commit a3c41dd

Browse files
authored
[WebAssembly] Guard use of getSymbolName with isSymbol (#156105)
WebAssemblyRegStackfy checks for writes to the stack pointer to avoid stackifying across them, but it wasn't prepared for other global_set instructions (such as writes in addrspace 1). Fixes #156055 Thanks to @QuantumSegfault for reporting and identifying the offending code.
1 parent 1cee0e7 commit a3c41dd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ static void query(const MachineInstr &MI, bool &Read, bool &Write,
247247
// Check for writes to __stack_pointer global.
248248
if ((MI.getOpcode() == WebAssembly::GLOBAL_SET_I32 ||
249249
MI.getOpcode() == WebAssembly::GLOBAL_SET_I64) &&
250-
strcmp(MI.getOperand(0).getSymbolName(), "__stack_pointer") == 0)
250+
MI.getOperand(0).isSymbol() &&
251+
!strcmp(MI.getOperand(0).getSymbolName(), "__stack_pointer"))
251252
StackPointer = true;
252253

253254
// Analyze calls.

llvm/test/CodeGen/WebAssembly/global-set.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ define void @set_f64_global(double %v) {
4545
ret void
4646
}
4747

48+
declare i32 @get_i32()
49+
define i32 @stackifyAcrossGlobalSet() {
50+
; https://github.com/llvm/llvm-project/issues/156055
51+
; CHECK-LABEL: stackifyAcrossGlobalSet:
52+
; CHECK-NEXT: .functype
53+
; CHECK-NEXT: .local
54+
; CHECK-NEXT: call get_i32
55+
; CHECK-NEXT: local.tee
56+
; CHECK-NEXT: global.set i32_global
57+
; CHECK-NEXT: local.get
58+
; CHECK-NEXT: end_function
59+
%1 = call i32 @get_i32()
60+
store i32 %1, ptr addrspace(1) @i32_global
61+
ret i32 %1
62+
}
63+
4864
; CHECK: .globaltype i32_global, i32
4965
; CHECK: .globl i32_global
5066
; CHECK-LABEL: i32_global:

0 commit comments

Comments
 (0)