[go/release-branch.go1.26] [release-branch.go1.26] cmd/compile: fix slice backing store analysis

5 views
Skip to first unread message

Cuong Manh Le (Gerrit)

unread,
Sep 22, 2026, 10:45:51 PMSep 22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Cuong Manh Le has uploaded the change for review

Commit message

[release-branch.go1.26] cmd/compile: fix slice backing store analysis

The range over slice statement keeps a pointer to the backing store of
the slice, making it from exclusive to nonexclusive at that point. Thus
we need to mark it as transition there.

Fixes #81689
Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Reviewed-by: Keith Randall <k...@golang.org>
Reviewed-by: Keith Randall <k...@google.com>
Reviewed-by: Cherry Mui <cher...@google.com>
Auto-Submit: Cuong Manh Le <cuong.m...@gmail.com>

Change diff

diff --git a/src/cmd/compile/internal/slice/slice.go b/src/cmd/compile/internal/slice/slice.go
index 17eba5b..8d8492a 100644
--- a/src/cmd/compile/internal/slice/slice.go
+++ b/src/cmd/compile/internal/slice/slice.go
@@ -356,10 +356,11 @@
}
}
case ir.ORANGE:
- // Range over slice is ok.
n := n.(*ir.RangeStmt)
if i := tracking(n.X); i != nil {
i.okUses++
+ // Range over slice keeps a pointer to the backing store, see #79909.
+ addTransition(i, n)
}
case ir.OAS:
n := n.(*ir.AssignStmt)
diff --git a/test/codegen/append.go b/test/codegen/append.go
index d232f0b..8d0d1f0 100644
--- a/test/codegen/append.go
+++ b/test/codegen/append.go
@@ -204,7 +204,9 @@
for i, x := range r {
println(i, x)
}
- // amd64:`.*moveSliceNoCapNoScan\b`
+ // "range r" keeps pointer to backing store of r, there
+ // should not be `moveSliceNoCapNoScan` here, see #79909.
+ // amd64:-`.*moveSliceNoCapNoScan\b`
return r
}

diff --git a/test/fixedbugs/issue79909.go b/test/fixedbugs/issue79909.go
new file mode 100644
index 0000000..ef34238
--- /dev/null
+++ b/test/fixedbugs/issue79909.go
@@ -0,0 +1,38 @@
+// run
+
+// Copyright 2026 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "strconv"
+
+var sink []int64
+
+//go:noinline
+func f() int64 {
+ var s []int64
+ for i := int64(1); i <= 4; i++ {
+ s = append(s, i)
+ }
+ if cap(s) != 4 {
+ return -1
+ }
+ sum := int64(0)
+ for idx, v := range s {
+ sum = sum*10 + v
+ if idx == 0 {
+ s = s[3:3]
+ s = append(s, 9, 9)
+ }
+ }
+ sink = s
+ return sum
+}
+
+func main() {
+ if got := f(); got != 1234 {
+ panic("unexpected result: " + strconv.Itoa(int(got)))
+ }
+}

Change information

Files:
  • M src/cmd/compile/internal/slice/slice.go
  • M test/codegen/append.go
  • A test/fixedbugs/issue79909.go
Change size: S
Delta: 3 files changed, 43 insertions(+), 2 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: release-branch.go1.26
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 837305
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
Sep 22, 2026, 10:46:07 PMSep 22
to goph...@pubsubhelper.golang.org, Keith Randall, golang-co...@googlegroups.com
Attention needed from Keith Randall

Cuong Manh Le voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: release-branch.go1.26
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 837305
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Comment-Date: Wed, 23 Sep 2026 02:45:58 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

David Chase (Gerrit)

unread,
Sep 29, 2026, 11:27:57 AMSep 29
to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le and Keith Randall

David Chase voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • Keith Randall
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: release-branch.go1.26
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 837305
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
Gerrit-Comment-Date: Tue, 29 Sep 2026 15:27:51 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Pratt (Gerrit)

unread,
Sep 30, 2026, 11:27:27 AMSep 30
to Cuong Manh Le, goph...@pubsubhelper.golang.org, Michael Pratt, David Chase, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le and Keith Randall

Michael Pratt voted

Auto-Submit+1
Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • Keith Randall
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: release-branch.go1.26
    Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
    Gerrit-Change-Number: 837305
    Gerrit-PatchSet: 1
    Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
    Gerrit-Comment-Date: Wed, 30 Sep 2026 15:27:21 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Sep 30, 2026, 11:35:05 AMSep 30
    to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Michael Pratt, David Chase, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, golang-co...@googlegroups.com

    Gopher Robot submitted the change

    Change information

    Commit message:
    [release-branch.go1.26] cmd/compile: fix slice backing store analysis

    The range over slice statement keeps a pointer to the backing store of
    the slice, making it from exclusive to nonexclusive at that point. Thus
    we need to mark it as transition there.

    Fixes #81689
    Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
    Reviewed-by: Keith Randall <k...@golang.org>
    Reviewed-by: Keith Randall <k...@google.com>
    Reviewed-by: Cherry Mui <cher...@google.com>
    Auto-Submit: Cuong Manh Le <cuong.m...@gmail.com>
    Reviewed-by: David Chase <drc...@google.com>
    Reviewed-by: Michael Pratt <mpr...@google.com>
    Auto-Submit: Michael Pratt <mpr...@google.com>
    Files:
    • M src/cmd/compile/internal/slice/slice.go
    • M test/codegen/append.go
    • A test/fixedbugs/issue79909.go
    Change size: S
    Delta: 3 files changed, 43 insertions(+), 2 deletions(-)
    Branch: refs/heads/release-branch.go1.26
    Submit Requirements:
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: go
    Gerrit-Branch: release-branch.go1.26
    Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
    Gerrit-Change-Number: 837305
    Gerrit-PatchSet: 2
    Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages