[go] cmd/compile: fix slice backing store analysis

1 view
Skip to first unread message

Cuong Manh Le (Gerrit)

unread,
3:12 AM (2 hours ago) 3:12 AM
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Cuong Manh Le has uploaded the change for review

Commit message

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 #79909
Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770

Change diff

diff --git a/src/cmd/compile/internal/slice/slice.go b/src/cmd/compile/internal/slice/slice.go
index 999469e..ed69b98 100644
--- a/src/cmd/compile/internal/slice/slice.go
+++ b/src/cmd/compile/internal/slice/slice.go
@@ -361,10 +361,13 @@
}
}
case ir.ORANGE:
- // Range over slice is ok.
n := n.(*ir.RangeStmt)
if i := tracking(n.X); i != nil {
i.okUses++
+ if n.X.Type().IsSlice() {
+ // 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/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
  • A test/fixedbugs/issue79909.go
Change size: S
Delta: 2 files changed, 42 insertions(+), 1 deletion(-)
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: master
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 789060
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
3:13 AM (2 hours ago) 3:13 AM
to goph...@pubsubhelper.golang.org, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Keith Randall and t hepudds

Cuong Manh Le voted

Auto-Submit+1
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • t hepudds
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: master
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 789060
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-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Comment-Date: Wed, 10 Jun 2026 07:13:03 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
3:49 AM (2 hours ago) 3:49 AM
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le, Keith Randall and t hepudds

Cuong Manh Le uploaded new patchset

Cuong Manh Le uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Cuong Manh Le
  • Keith Randall
  • t hepudds
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: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 789060
Gerrit-PatchSet: 2
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-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
3:49 AM (2 hours ago) 3:49 AM
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, t hepudds, golang-co...@googlegroups.com
Attention needed from Keith Randall and t hepudds

Cuong Manh Le voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Keith Randall
  • t hepudds
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: master
Gerrit-Change-Id: I7292b5644ac658fa3a6ccd9fa949b454d2f3d770
Gerrit-Change-Number: 789060
Gerrit-PatchSet: 2
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-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: t hepudds <thepud...@gmail.com>
Gerrit-Comment-Date: Wed, 10 Jun 2026 07:49:27 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages