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)))
+ }
+}