From eef5f8d93016147718afba8a05282d2ba7332c51 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 1 Aug 2025 07:38:55 -0700 Subject: [PATCH] cmd/compile: enforce that locals are always accessed with SP base register After CL 678937, we could have a situation where the value of the stack pointer is in both SP and another register. We need to make sure that regalloc picks SP when issuing a reference to local variables; the assembler expects that. Fixes #74836 Change-Id: I2ac73ece6eb44b4a78c1369f8a69e51ab9748754 Reviewed-on: https://go-review.googlesource.com/c/go/+/692395 Reviewed-by: Cuong Manh Le Reviewed-by: Keith Randall Reviewed-by: Mark Freeman LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/ssa/regalloc.go | 6 ++++++ test/fixedbugs/issue74836.go | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/fixedbugs/issue74836.go diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index de49bb40c5..fb9642cfed 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -1583,6 +1583,12 @@ func (s *regAllocState) regalloc(f *Func) { mask &^= desired.avoid } } + if mask&s.values[v.Args[i.idx].ID].regs&(1<