From 02227173776bb286585db6c124432972da2a9580 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 21 Jan 2026 14:39:20 +0700 Subject: [PATCH] [release-branch.go1.25] cmd/compile: fix mis-compilation for static array initialization The bug was first introduced when the compiler is still written in C, with CL 2254041. The static array was laid out with the wrong context, causing a stack pointer will be stored in global object. Fixes #77253 Change-Id: I22c8393314d251beb53db537043a63714c84f36a Reviewed-on: https://go-review.googlesource.com/c/go/+/737821 Reviewed-by: Dmitri Shuralyov Reviewed-by: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Auto-Submit: Keith Randall Reviewed-on: https://go-review.googlesource.com/c/go/+/738440 Reviewed-by: Cherry Mui --- src/cmd/compile/internal/walk/complit.go | 6 +----- test/codegen/slices.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go index 6452618f6c..1bc4d42c88 100644 --- a/src/cmd/compile/internal/walk/complit.go +++ b/src/cmd/compile/internal/walk/complit.go @@ -567,11 +567,7 @@ func anylit(n ir.Node, var_ ir.Node, init *ir.Nodes) { // lay out static data vstat := readonlystaticname(t) - ctxt := inInitFunction - if n.Op() == ir.OARRAYLIT { - ctxt = inNonInitFunction - } - fixedlit(ctxt, initKindStatic, n, vstat, init) + fixedlit(inInitFunction, initKindStatic, n, vstat, init) // copy static to var appendWalkStmt(init, ir.NewAssignStmt(base.Pos, var_, vstat)) diff --git a/test/codegen/slices.go b/test/codegen/slices.go index 9e8990c586..5d57f0099a 100644 --- a/test/codegen/slices.go +++ b/test/codegen/slices.go @@ -429,3 +429,15 @@ func Slice0(p *struct{}, i int) []struct{} { // amd64:-"MULQ" return unsafe.Slice(p, i) } + +func Issue61730() { + var x int + // amd64:-"MOVQ .*stmp_" + _ = [...][]*int{ + {&x}, + nil, + nil, + nil, + nil, + } +} -- 2.52.0