]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix mis-compilation for static array initialization
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 21 Jan 2026 07:39:20 +0000 (14:39 +0700)
committerGopher Robot <gobot@golang.org>
Thu, 22 Jan 2026 15:30:19 +0000 (07:30 -0800)
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 #61730
Fixes #77193

Change-Id: I22c8393314d251beb53db537043a63714c84f36a
Reviewed-on: https://go-review.googlesource.com/c/go/+/737821
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>

src/cmd/compile/internal/walk/complit.go
test/codegen/slices.go

index 6452618f6cead70ff2ccfc19b66e89c3eb329fde..1bc4d42c886800b162edcdee82f7410b5ec3b4d0 100644 (file)
@@ -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))
index 1c48b38047e841aecb495f3c76d57cc6868b286f..32561b2235151e0d8a5989d24d61ed10f82e9f53 100644 (file)
@@ -456,3 +456,15 @@ func SlicePut(a []byte, c uint8) []byte {
        a = a[1:]
        return a
 }
+
+func Issue61730() {
+       var x int
+       // amd64:-"MOVQ .*stmp_"
+       _ = [...][]*int{
+               {&x},
+               nil,
+               nil,
+               nil,
+               nil,
+       }
+}