[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.
This commit is contained in:
Derek Schuff 2025-09-02 16:21:35 -07:00 committed by GitHub
parent 1cee0e7b62
commit a3c41ddcaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -247,7 +247,8 @@ static void query(const MachineInstr &MI, bool &Read, bool &Write,
// Check for writes to __stack_pointer global.
if ((MI.getOpcode() == WebAssembly::GLOBAL_SET_I32 ||
MI.getOpcode() == WebAssembly::GLOBAL_SET_I64) &&
strcmp(MI.getOperand(0).getSymbolName(), "__stack_pointer") == 0)
MI.getOperand(0).isSymbol() &&
!strcmp(MI.getOperand(0).getSymbolName(), "__stack_pointer"))
StackPointer = true;
// Analyze calls.

View file

@ -45,6 +45,22 @@ define void @set_f64_global(double %v) {
ret void
}
declare i32 @get_i32()
define i32 @stackifyAcrossGlobalSet() {
; https://github.com/llvm/llvm-project/issues/156055
; CHECK-LABEL: stackifyAcrossGlobalSet:
; CHECK-NEXT: .functype
; CHECK-NEXT: .local
; CHECK-NEXT: call get_i32
; CHECK-NEXT: local.tee
; CHECK-NEXT: global.set i32_global
; CHECK-NEXT: local.get
; CHECK-NEXT: end_function
%1 = call i32 @get_i32()
store i32 %1, ptr addrspace(1) @i32_global
ret i32 %1
}
; CHECK: .globaltype i32_global, i32
; CHECK: .globl i32_global
; CHECK-LABEL: i32_global: