diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2026-01-21 14:39:20 +0700 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2026-02-25 11:16:21 -0800 |
| commit | 85050c90ee22ef662dcf455a52ab050e8a4d8409 (patch) | |
| tree | f95ab4d891de3dbabb4c7b4a1d4bba252b9a58b4 | |
| parent | 12c0690eebcccf3f1aeaf7599c044edbd7ae7798 (diff) | |
| download | go-85050c90ee22ef662dcf455a52ab050e8a4d8409.tar.xz | |
[release-branch.go1.26] 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 #77252
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>
(cherry picked from commit dae71067ce7ee41ebe752a4ee3c544506e74f824)
Reviewed-on: https://go-review.googlesource.com/c/go/+/738940
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
| -rw-r--r-- | src/cmd/compile/internal/walk/complit.go | 6 | ||||
| -rw-r--r-- | 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 1c48b38047..32561b2235 100644 --- a/test/codegen/slices.go +++ b/test/codegen/slices.go @@ -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, + } +} |
