[go] cmd/compile: recursively insert bounds checks for zero-sized arrays

10 views
Skip to first unread message

Cuong Manh Le (Gerrit)

unread,
May 7, 2026, 6:43:13 AM (12 days ago) May 7
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Cuong Manh Le has uploaded the change for review

Commit message

cmd/compile: recursively insert bounds checks for zero-sized arrays

CL 774120 attempted to fix missing bounds checks for zero-sized arrays,
but the implementation was incomplete. It failed to account for nested
zero-sized types, where an index operation might still require a check
despite the inner element size.

This change generalizes the fix by recursively walking the IR nodes
and ensuring a bounds check is inserted for every array index
operation encountered, regardless of nesting depth.

Updates #79197
Fixes #79236
Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497

Change diff

diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go
index d049631..5c57c31 100644
--- a/src/cmd/compile/internal/ssagen/ssa.go
+++ b/src/cmd/compile/internal/ssagen/ssa.go
@@ -4546,11 +4546,11 @@
// they are somewhere inside an outer [0].
// We can ignore the actual assignment, it is dynamically
// unreachable. See issue 77635.
+ s.boundsCheckArrayIndex(left)
return
}
if t.Size() == 0 {
- len := s.constInt(types.Types[types.TINT], n)
- s.boundsCheck(i, len, ssa.BoundsIndex, false)
+ s.boundsCheckArrayIndex(left)
return
}

@@ -5262,6 +5262,7 @@
// &x[i], which will always panic when evaluated.
// We just return something reasonable in this case.
// It will be dynamically unreachable. See issue 77635.
+ s.boundsCheckArrayIndex(n)
return s.newValue1A(ssa.OpAddr, n.Type().PtrTo(), ir.Syms.Zerobase, s.sb)
}

@@ -5444,6 +5445,25 @@
return s.newValue2(ssa.OpNilCheck, ptr.Type, ptr, s.mem())
}

+// boundsCheckArrayIndex performs bounds checking recursively for indexed array expressions.
+func (s *state) boundsCheckArrayIndex(n ir.Node) {
+ for {
+ nn := n
+ if nn.Op() == ir.OINDEX {
+ nn := nn.(*ir.IndexExpr)
+ typ := nn.X.Type()
+ if typ.IsArray() {
+ idx := s.expr(nn.Index)
+ len := s.constInt(types.Types[types.TINT], typ.NumElem())
+ s.boundsCheck(idx, len, ssa.BoundsIndex, nn.Bounded())
+ n = nn.X
+ continue
+ }
+ }
+ break
+ }
+}
+
// boundsCheck generates bounds checking code. Checks if 0 <= idx <[=] len, branches to exit if not.
// Starts a new block on return.
// On input, len must be converted to full int width and be nonnegative.
diff --git a/test/fixedbugs/issue79236.go b/test/fixedbugs/issue79236.go
new file mode 100644
index 0000000..f09c937
--- /dev/null
+++ b/test/fixedbugs/issue79236.go
@@ -0,0 +1,41 @@
+// 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
+
+//go:noinline
+func a1(i int) {
+ var a [2][0]int
+ a[i] = [0]int{}
+}
+
+//go:noinline
+func a2(i int) int {
+ var a [0][2]int
+ return a[i][0]
+}
+
+//go:noinline
+func a3(i int) {
+ var a [0][2]int
+ a[i][0] = 1
+}
+
+func wantPanic(name string, f func()) {
+ defer func() {
+ if r := recover(); r != nil {
+ return
+ }
+ panic(name + ": no panic (bug)")
+ }()
+ f()
+}
+
+func main() {
+ wantPanic("a1", func() { a1(5) })
+ wantPanic("a2", func() { _ = a2(5) })
+ wantPanic("a3", func() { a3(5) })
+}

Change information

Files:
  • M src/cmd/compile/internal/ssagen/ssa.go
  • A test/fixedbugs/issue79236.go
Change size: M
Delta: 2 files changed, 63 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: master
Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
Gerrit-Change-Number: 775120
Gerrit-PatchSet: 1
Gerrit-Owner: Cuong Manh Le <cuong.m...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 7, 2026, 6:43:43 AM (12 days ago) May 7
to goph...@pubsubhelper.golang.org, Keith Randall, David Chase, Josh Bleecher Snyder, golang-co...@googlegroups.com
Attention needed from David Chase, Josh Bleecher Snyder and Keith Randall

Cuong Manh Le voted

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

Related details

Attention is currently required from:
  • David Chase
  • Josh Bleecher Snyder
  • 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: master
Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
Gerrit-Change-Number: 775120
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: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: David Chase <drc...@google.com>
Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Comment-Date: Thu, 07 May 2026 10:43:38 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 7, 2026, 7:13:12 AM (12 days ago) May 7
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, David Chase, Josh Bleecher Snyder, golang-co...@googlegroups.com
Attention needed from David Chase, Josh Bleecher Snyder and Keith Randall

Cuong Manh Le voted Commit-Queue+1

Gerrit-Attention: Keith Randall <k...@golang.org>
Gerrit-Attention: David Chase <drc...@google.com>
Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
Gerrit-Comment-Date: Thu, 07 May 2026 11:13:06 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Cuong Manh Le (Gerrit)

unread,
May 7, 2026, 7:31:10 AM (12 days ago) May 7
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, David Chase, Josh Bleecher Snyder, golang-co...@googlegroups.com
Gerrit-Comment-Date: Thu, 07 May 2026 11:31:03 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

David Chase (Gerrit)

unread,
May 7, 2026, 8:08:17 AM (12 days ago) May 7
to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
Attention needed from Cuong Manh Le, Josh Bleecher Snyder 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
  • Josh Bleecher Snyder
  • 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: master
    Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
    Gerrit-Change-Number: 775120
    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: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Attention: Keith Randall <k...@golang.org>
    Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Comment-Date: Thu, 07 May 2026 12:08:12 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Keith Randall (Gerrit)

    unread,
    May 7, 2026, 11:57:03 AM (12 days ago) May 7
    to Cuong Manh Le, goph...@pubsubhelper.golang.org, David Chase, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
    Attention needed from Cuong Manh Le and Josh Bleecher Snyder

    Keith Randall added 2 comments

    File src/cmd/compile/internal/ssagen/ssa.go
    Line 4561, Patchset 1 (Parent): s.assign(left.X, v, false, 0)
    Keith Randall . unresolved

    Seems reasonable, but I think the underlying problem here is we don't evaluate `left.X` in either of the cases above (like we do in this line). Could there be other things with side effects in there, other than index panics?

    Line 5451, Patchset 1 (Latest): nn := n
    Keith Randall . unresolved

    This `nn` seems unnecessary.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Cuong Manh Le
    • Josh Bleecher Snyder
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement is not 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: master
    Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
    Gerrit-Change-Number: 775120
    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: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Reviewer: Keith Randall <k...@golang.org>
    Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
    Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
    Gerrit-Comment-Date: Thu, 07 May 2026 15:56:58 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Cuong Manh Le (Gerrit)

    unread,
    May 7, 2026, 12:57:33 PM (12 days ago) May 7
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Cuong Manh Le and Josh Bleecher Snyder

    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
    • Josh Bleecher Snyder
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
      Gerrit-Change-Number: 775120
      Gerrit-PatchSet: 2
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      May 7, 2026, 12:59:47 PM (12 days ago) May 7
      to goph...@pubsubhelper.golang.org, David Chase, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
      Attention needed from Josh Bleecher Snyder and Keith Randall

      Cuong Manh Le voted and added 2 comments

      Votes added by Cuong Manh Le

      Auto-Submit+1
      Commit-Queue+1

      2 comments

      File src/cmd/compile/internal/ssagen/ssa.go
      Line 4561, Patchset 1 (Parent): s.assign(left.X, v, false, 0)
      Keith Randall . unresolved

      Seems reasonable, but I think the underlying problem here is we don't evaluate `left.X` in either of the cases above (like we do in this line). Could there be other things with side effects in there, other than index panics?

      Cuong Manh Le

      Seems reasonable, but I think the underlying problem here is we don't evaluate left.X in either of the cases above (like we do in this line)

      Ah right, then I think we can simplify `s.boundsCheckArrayIndex` by evaluating `n.X`.

      Could there be other things with side effects in there, other than index panics?

      I could not think off-hand, but just evaluating left.X like you suggested above is safer.

      Line 5451, Patchset 1: nn := n
      Keith Randall . resolved

      This `nn` seems unnecessary.

      Cuong Manh Le

      Acknowledged

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Josh Bleecher Snyder
      • Keith Randall
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
      Gerrit-Change-Number: 775120
      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: Josh Bleecher Snyder <josh...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
      Gerrit-Comment-Date: Thu, 07 May 2026 16:59:40 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Keith Randall <k...@golang.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      May 7, 2026, 1:02:22 PM (12 days ago) May 7
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
      Attention needed from Cuong Manh Le, Josh Bleecher Snyder and Keith Randall

      Cuong Manh Le uploaded new patchset

      Cuong Manh Le uploaded patch set #3 to this change.
      Open in Gerrit

      Related details

      Attention is currently required from:
      • Cuong Manh Le
      • Josh Bleecher Snyder
      • Keith Randall
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
      Gerrit-Change-Number: 775120
      Gerrit-PatchSet: 3
      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: Josh Bleecher Snyder <josh...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      May 7, 2026, 1:02:56 PM (12 days ago) May 7
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
      Attention needed from Josh Bleecher Snyder and Keith Randall

      Cuong Manh Le voted

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

      Related details

      Attention is currently required from:
      • Josh Bleecher Snyder
      • Keith Randall
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
      Gerrit-Change-Number: 775120
      Gerrit-PatchSet: 3
      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: Josh Bleecher Snyder <josh...@gmail.com>
      Gerrit-Reviewer: Keith Randall <k...@golang.org>
      Gerrit-Attention: Keith Randall <k...@golang.org>
      Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
      Gerrit-Comment-Date: Thu, 07 May 2026 17:02:40 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Cuong Manh Le (Gerrit)

      unread,
      May 8, 2026, 8:18:44 PM (10 days ago) May 8
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
      Attention needed from Josh Bleecher Snyder and Keith Randall

      Cuong Manh Le added 1 comment

      Patchset-level comments
      File-level comment, Patchset 3 (Latest):
      Cuong Manh Le . resolved

      @k...@golang.org a gentle ping

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Josh Bleecher Snyder
      • Keith Randall
      Submit Requirements:
        • requirement satisfiedCode-Review
        • requirement is not 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: master
        Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
        Gerrit-Change-Number: 775120
        Gerrit-PatchSet: 3
        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: Josh Bleecher Snyder <josh...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Attention: Keith Randall <k...@golang.org>
        Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
        Gerrit-Comment-Date: Sat, 09 May 2026 00:18:36 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        Keith Randall (Gerrit)

        unread,
        May 8, 2026, 8:32:53 PM (10 days ago) May 8
        to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
        Attention needed from Cuong Manh Le and Josh Bleecher Snyder

        Keith Randall added 3 comments

        File src/cmd/compile/internal/ssagen/ssa.go
        Line 4548, Patchset 3 (Parent): // unreachable. See issue 77635.
        Keith Randall . unresolved

        Maybe just `_ = s.expr(left.X)` would be enough here?
        We don't actually need the outermost bounds check. It is guaranteed not to even reach it.

        Line 4552, Patchset 3 (Parent): len := s.constInt(types.Types[types.TINT], n)
        Keith Randall . unresolved

        We would need the `expr` call here also.

        (But maybe `expr` isn't right if the value isn't ssa-able? Then maybe we need `.addr` instead. That could use a `evalForSideEffects` or some such function that picks between the two.)

        Line 5457, Patchset 3 (Latest): idx := s.expr(nn.Index)
        Keith Randall . unresolved

        I think we already evaluated this in the caller? We would have to pass in the already-computed *ssa.Value, I think. Don't want to evaluate the index twice.

        Open in Gerrit

        Related details

        Attention is currently required from:
        • Cuong Manh Le
        • Josh Bleecher Snyder
        Submit Requirements:
        • requirement satisfiedCode-Review
        • requirement is not 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: master
        Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
        Gerrit-Change-Number: 775120
        Gerrit-PatchSet: 3
        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: Josh Bleecher Snyder <josh...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
        Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
        Gerrit-Comment-Date: Sat, 09 May 2026 00:32:49 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy

        David Chase (Gerrit)

        unread,
        May 8, 2026, 9:24:12 PM (10 days ago) May 8
        to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
        Attention needed from Cuong Manh Le and Josh Bleecher Snyder

        David Chase voted Code-Review+0

        Code-Review+0
        Open in Gerrit

        Related details

        Attention is currently required from:
        • Cuong Manh Le
        • Josh Bleecher Snyder
        Submit Requirements:
        • requirement is not satisfiedCode-Review
        • requirement is not 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: master
        Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
        Gerrit-Change-Number: 775120
        Gerrit-PatchSet: 3
        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: Josh Bleecher Snyder <josh...@gmail.com>
        Gerrit-Reviewer: Keith Randall <k...@golang.org>
        Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
        Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
        Gerrit-Comment-Date: Sat, 09 May 2026 01:24:09 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Cuong Manh Le (Gerrit)

        unread,
        May 9, 2026, 1:30:49 PM (10 days ago) May 9
        to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
        Attention needed from Cuong Manh Le and Josh Bleecher Snyder

        Cuong Manh Le uploaded new patchset

        Cuong Manh Le uploaded patch set #4 to this change.
        Following approvals got outdated and were removed:

        Related details

        Attention is currently required from:
        • Cuong Manh Le
        • Josh Bleecher Snyder
        Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
          Gerrit-Change-Number: 775120
          Gerrit-PatchSet: 4
          unsatisfied_requirement
          open
          diffy

          Cuong Manh Le (Gerrit)

          unread,
          May 9, 2026, 1:31:14 PM (10 days ago) May 9
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
          Attention needed from Josh Bleecher Snyder and Keith Randall

          Cuong Manh Le voted and added 4 comments

          Votes added by Cuong Manh Le

          Auto-Submit+1
          Commit-Queue+1

          4 comments

          File src/cmd/compile/internal/ssagen/ssa.go
          Line 4548, Patchset 3 (Parent): // unreachable. See issue 77635.
          Keith Randall . unresolved

          Maybe just `_ = s.expr(left.X)` would be enough here?
          We don't actually need the outermost bounds check. It is guaranteed not to even reach it.

          Cuong Manh Le

          Nope, in case of `a1` function:

          ```
          //go:noinline
          func a1(i int) {

          var a [2][0]int
          	a[i] = [0]int{}
          }
          ```

          `left.X` will be `a`, thus calling `s.expr(left.X)` leads to missing bound checks.

          Line 4552, Patchset 3 (Parent): len := s.constInt(types.Types[types.TINT], n)
          Keith Randall . resolved

          We would need the `expr` call here also.

          (But maybe `expr` isn't right if the value isn't ssa-able? Then maybe we need `.addr` instead. That could use a `evalForSideEffects` or some such function that picks between the two.)

          Cuong Manh Le

          Done

          Line 4561, Patchset 1 (Parent): s.assign(left.X, v, false, 0)
          Keith Randall . resolved

          Seems reasonable, but I think the underlying problem here is we don't evaluate `left.X` in either of the cases above (like we do in this line). Could there be other things with side effects in there, other than index panics?

          Cuong Manh Le

          Seems reasonable, but I think the underlying problem here is we don't evaluate left.X in either of the cases above (like we do in this line)

          Ah right, then I think we can simplify `s.boundsCheckArrayIndex` by evaluating `n.X`.

          Could there be other things with side effects in there, other than index panics?

          I could not think off-hand, but just evaluating left.X like you suggested above is safer.

          Cuong Manh Le

          Done

          Line 5457, Patchset 3: idx := s.expr(nn.Index)
          Keith Randall . resolved

          I think we already evaluated this in the caller? We would have to pass in the already-computed *ssa.Value, I think. Don't want to evaluate the index twice.

          Cuong Manh Le

          Done

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Josh Bleecher Snyder
          • Keith Randall
          Submit Requirements:
          • requirement is not satisfiedCode-Review
          • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
          Gerrit-Change-Number: 775120
          Gerrit-PatchSet: 4
          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: Josh Bleecher Snyder <josh...@gmail.com>
          Gerrit-Reviewer: Keith Randall <k...@golang.org>
          Gerrit-Attention: Keith Randall <k...@golang.org>
          Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
          Gerrit-Comment-Date: Sat, 09 May 2026 17:31:04 +0000
          Gerrit-HasComments: Yes
          Gerrit-Has-Labels: Yes
          Comment-In-Reply-To: Keith Randall <k...@golang.org>
          Comment-In-Reply-To: Cuong Manh Le <cuong.m...@gmail.com>
          unsatisfied_requirement
          open
          diffy

          Cuong Manh Le (Gerrit)

          unread,
          May 13, 2026, 9:05:19 PM (5 days ago) May 13
          to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
          Attention needed from Josh Bleecher Snyder and Keith Randall

          Cuong Manh Le added 1 comment

          File src/cmd/compile/internal/ssagen/ssa.go
          Line 4548, Patchset 3 (Parent): // unreachable. See issue 77635.
          Keith Randall . unresolved

          Maybe just `_ = s.expr(left.X)` would be enough here?
          We don't actually need the outermost bounds check. It is guaranteed not to even reach it.

          Cuong Manh Le

          Nope, in case of `a1` function:

          ```
          //go:noinline
          func a1(i int) {
          var a [2][0]int
          a[i] = [0]int{}
          }
          ```

          `left.X` will be `a`, thus calling `s.expr(left.X)` leads to missing bound checks.

          Cuong Manh Le

          Hey @khr@golang.oỏg, a gentle ping 😊

          Open in Gerrit

          Related details

          Attention is currently required from:
          • Josh Bleecher Snyder
          • Keith Randall
          Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not 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: master
            Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
            Gerrit-Change-Number: 775120
            Gerrit-PatchSet: 4
            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: Josh Bleecher Snyder <josh...@gmail.com>
            Gerrit-Reviewer: Keith Randall <k...@golang.org>
            Gerrit-Attention: Keith Randall <k...@golang.org>
            Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
            Gerrit-Comment-Date: Thu, 14 May 2026 01:05:14 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Cuong Manh Le (Gerrit)

            unread,
            May 14, 2026, 1:39:51 PM (5 days ago) May 14
            to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
            Attention needed from Josh Bleecher Snyder and Keith Randall

            Cuong Manh Le added 1 comment

            File src/cmd/compile/internal/ssagen/ssa.go
            Line 4548, Patchset 3 (Parent): // unreachable. See issue 77635.
            Keith Randall . unresolved

            Maybe just `_ = s.expr(left.X)` would be enough here?
            We don't actually need the outermost bounds check. It is guaranteed not to even reach it.

            Cuong Manh Le

            Nope, in case of `a1` function:

            ```
            //go:noinline
            func a1(i int) {
            var a [2][0]int
            a[i] = [0]int{}
            }
            ```

            `left.X` will be `a`, thus calling `s.expr(left.X)` leads to missing bound checks.

            Cuong Manh Le

            Hey @khr@golang.oỏg, a gentle ping 😊

            Cuong Manh Le

            Ops, my typo.

            @k...@golang.org

            Gerrit-Comment-Date: Thu, 14 May 2026 17:39:47 +0000
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Keith Randall (Gerrit)

            unread,
            May 14, 2026, 5:03:12 PM (5 days ago) May 14
            to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
            Attention needed from Cuong Manh Le and Josh Bleecher Snyder

            Keith Randall added 1 comment

            File src/cmd/compile/internal/ssagen/ssa.go
            Line 4548, Patchset 3 (Parent): // unreachable. See issue 77635.
            Keith Randall . unresolved

            Maybe just `_ = s.expr(left.X)` would be enough here?
            We don't actually need the outermost bounds check. It is guaranteed not to even reach it.

            Cuong Manh Le

            Nope, in case of `a1` function:

            ```
            //go:noinline
            func a1(i int) {
            var a [2][0]int
            a[i] = [0]int{}
            }
            ```

            `left.X` will be `a`, thus calling `s.expr(left.X)` leads to missing bound checks.

            Cuong Manh Le

            Hey @khr@golang.oỏg, a gentle ping 😊

            Cuong Manh Le

            Ops, my typo.

            @k...@golang.org

            Keith Randall

            Ah, ok.

            Then this comment needs updating. There are cases here where it is not always-panic. Those are always 0-size assignment cases?

            Maybe it would be clearer to do the `t.Size()==0` case before the `n != 1` case?

            Open in Gerrit

            Related details

            Attention is currently required from:
            • Cuong Manh Le
            • Josh Bleecher Snyder
            Submit Requirements:
            • requirement is not satisfiedCode-Review
            • requirement is not 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: master
            Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
            Gerrit-Change-Number: 775120
            Gerrit-PatchSet: 4
            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: Josh Bleecher Snyder <josh...@gmail.com>
            Gerrit-Reviewer: Keith Randall <k...@golang.org>
            Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
            Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
            Gerrit-Comment-Date: Thu, 14 May 2026 21:03:08 +0000
            unsatisfied_requirement
            satisfied_requirement
            open
            diffy

            Cuong Manh Le (Gerrit)

            unread,
            May 14, 2026, 6:50:14 PM (5 days ago) May 14
            to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
            Attention needed from Cuong Manh Le and Josh Bleecher Snyder

            Cuong Manh Le uploaded new patchset

            Cuong Manh Le uploaded patch set #5 to this change.
            Following approvals got outdated and were removed:

            Related details

            Attention is currently required from:
            • Cuong Manh Le
            • Josh Bleecher Snyder
            Submit Requirements:
              • requirement is not satisfiedCode-Review
              • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
              Gerrit-Change-Number: 775120
              Gerrit-PatchSet: 5
              unsatisfied_requirement
              open
              diffy

              Cuong Manh Le (Gerrit)

              unread,
              May 14, 2026, 6:50:58 PM (5 days ago) May 14
              to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
              Attention needed from Josh Bleecher Snyder and Keith Randall

              Cuong Manh Le voted and added 1 comment

              Votes added by Cuong Manh Le

              Auto-Submit+1
              Commit-Queue+1

              1 comment

              File src/cmd/compile/internal/ssagen/ssa.go
              Line 4548, Patchset 3 (Parent): // unreachable. See issue 77635.
              Keith Randall . resolved

              Maybe just `_ = s.expr(left.X)` would be enough here?
              We don't actually need the outermost bounds check. It is guaranteed not to even reach it.

              Cuong Manh Le

              Nope, in case of `a1` function:

              ```
              //go:noinline
              func a1(i int) {
              var a [2][0]int
              a[i] = [0]int{}
              }
              ```

              `left.X` will be `a`, thus calling `s.expr(left.X)` leads to missing bound checks.

              Cuong Manh Le

              Hey @khr@golang.oỏg, a gentle ping 😊

              Cuong Manh Le

              Ops, my typo.

              @k...@golang.org

              Keith Randall

              Ah, ok.

              Then this comment needs updating. There are cases here where it is not always-panic. Those are always 0-size assignment cases?

              Maybe it would be clearer to do the `t.Size()==0` case before the `n != 1` case?

              Cuong Manh Le

              Maybe it would be clearer to do the t.Size()==0 case before the n != 1 case?

              Fair enough, then we don't have to update the comment for n != 1 case.

              Open in Gerrit

              Related details

              Attention is currently required from:
              • Josh Bleecher Snyder
              • 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: master
                Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
                Gerrit-Change-Number: 775120
                Gerrit-PatchSet: 5
                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: Josh Bleecher Snyder <josh...@gmail.com>
                Gerrit-Reviewer: Keith Randall <k...@golang.org>
                Gerrit-Attention: Keith Randall <k...@golang.org>
                Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
                Gerrit-Comment-Date: Thu, 14 May 2026 22:50:55 +0000
                Gerrit-HasComments: Yes
                Gerrit-Has-Labels: Yes
                unsatisfied_requirement
                satisfied_requirement
                open
                diffy

                Keith Randall (Gerrit)

                unread,
                May 14, 2026, 9:45:50 PM (4 days ago) May 14
                to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
                Attention needed from Cuong Manh Le and Josh Bleecher Snyder

                Keith Randall added 3 comments

                File src/cmd/compile/internal/ssagen/ssa.go
                Line 4532, Patchset 5 (Parent): s.boundsCheck(z, z, ssa.BoundsIndex, false)
                Keith Randall . unresolved

                Does this need a special case also?

                ```
                func f() [0]int { ... }
                f()[i] = 3
                ```
                We still do want to evaluate `f()`.

                Line 4538, Patchset 5 (Latest): s.boundsCheckArrayIndex(left, i)
                Keith Randall . unresolved

                This needs to be left.X, to avoid re-evaluating the index.

                Line 4550, Patchset 5 (Latest): s.boundsCheckArrayIndex(left.X, nil)
                Keith Randall . unresolved

                This is weird, because we know nothing about left.X. I see no reason why it is necessarily an array index. I think we just want a "eval this expr and throw away the result" evaluator.

                Open in Gerrit

                Related details

                Attention is currently required from:
                • Cuong Manh Le
                • Josh Bleecher Snyder
                Submit Requirements:
                  • requirement is not satisfiedCode-Review
                  • requirement is not 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: master
                  Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
                  Gerrit-Change-Number: 775120
                  Gerrit-PatchSet: 5
                  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: Josh Bleecher Snyder <josh...@gmail.com>
                  Gerrit-Reviewer: Keith Randall <k...@golang.org>
                  Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
                  Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
                  Gerrit-Comment-Date: Fri, 15 May 2026 01:45:44 +0000
                  Gerrit-HasComments: Yes
                  Gerrit-Has-Labels: No
                  unsatisfied_requirement
                  satisfied_requirement
                  open
                  diffy

                  Cuong Manh Le (Gerrit)

                  unread,
                  May 15, 2026, 2:31:15 AM (4 days ago) May 15
                  to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
                  Attention needed from Cuong Manh Le and Josh Bleecher Snyder

                  Cuong Manh Le uploaded new patchset

                  Cuong Manh Le uploaded patch set #6 to this change.
                  Following approvals got outdated and were removed:

                  Related details

                  Attention is currently required from:
                  • Cuong Manh Le
                  • Josh Bleecher Snyder
                  Submit Requirements:
                    • requirement is not satisfiedCode-Review
                    • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
                    Gerrit-Change-Number: 775120
                    Gerrit-PatchSet: 6
                    unsatisfied_requirement
                    open
                    diffy

                    Cuong Manh Le (Gerrit)

                    unread,
                    May 15, 2026, 2:31:43 AM (4 days ago) May 15
                    to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
                    Attention needed from Josh Bleecher Snyder and Keith Randall

                    Cuong Manh Le voted and added 3 comments

                    Votes added by Cuong Manh Le

                    Auto-Submit+1
                    Commit-Queue+1

                    3 comments

                    File src/cmd/compile/internal/ssagen/ssa.go
                    Line 4532, Patchset 5 (Parent): s.boundsCheck(z, z, ssa.BoundsIndex, false)
                    Keith Randall . unresolved

                    Does this need a special case also?

                    ```
                    func f() [0]int { ... }
                    f()[i] = 3
                    ```
                    We still do want to evaluate `f()`.

                    Cuong Manh Le

                    Hmm, `f()[i]` is not addressable, so it even does not pass typechecker.

                    Further, even in case it passes, I believe order pass ensures `f()` was evaluated before we reach here, by re-written in roughly to:

                    ```
                    tmp = f()
                    tmp[i] = 3
                    ```

                    Line 4538, Patchset 5: s.boundsCheckArrayIndex(left, i)
                    Keith Randall . unresolved

                    This needs to be left.X, to avoid re-evaluating the index.

                    Cuong Manh Le

                    Wait, the index belongs to `left`, not `left.X`. For example, with `a[i] = [0]int{}` case above, we have `left` is `a[i]`, `left.X` is `a`, and the index is `i`. So we do want to call `s.boundsCheckArrayIndex(a[i], i)`, so we won't re-evaluate `i`.

                    Line 4550, Patchset 5: s.boundsCheckArrayIndex(left.X, nil)
                    Keith Randall . resolved

                    This is weird, because we know nothing about left.X. I see no reason why it is necessarily an array index. I think we just want a "eval this expr and throw away the result" evaluator.

                    Cuong Manh Le

                    Acknowledged

                    Open in Gerrit

                    Related details

                    Attention is currently required from:
                    • Josh Bleecher Snyder
                    • Keith Randall
                    Submit Requirements:
                    • requirement is not satisfiedCode-Review
                    • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
                    Gerrit-Change-Number: 775120
                    Gerrit-PatchSet: 6
                    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: Josh Bleecher Snyder <josh...@gmail.com>
                    Gerrit-Reviewer: Keith Randall <k...@golang.org>
                    Gerrit-Attention: Keith Randall <k...@golang.org>
                    Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
                    Gerrit-Comment-Date: Fri, 15 May 2026 06:31:39 +0000
                    unsatisfied_requirement
                    open
                    diffy

                    Keith Randall (Gerrit)

                    unread,
                    May 15, 2026, 3:02:24 PM (4 days ago) May 15
                    to Cuong Manh Le, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
                    Attention needed from Cuong Manh Le and Josh Bleecher Snyder

                    Keith Randall added 2 comments

                    File src/cmd/compile/internal/ssagen/ssa.go
                    Line 4532, Patchset 5 (Parent): s.boundsCheck(z, z, ssa.BoundsIndex, false)
                    Keith Randall . unresolved

                    Does this need a special case also?

                    ```
                    func f() [0]int { ... }
                    f()[i] = 3
                    ```
                    We still do want to evaluate `f()`.

                    Cuong Manh Le

                    Hmm, `f()[i]` is not addressable, so it even does not pass typechecker.

                    Further, even in case it passes, I believe order pass ensures `f()` was evaluated before we reach here, by re-written in roughly to:

                    ```
                    tmp = f()
                    tmp[i] = 3
                    ```

                    Keith Randall

                    I guess I meant something generically side-effecting in place of `f()`. For example,

                    var x *[0]int
                    (*x)[i] = 3

                    should nil panic, not bounds panic?

                    Line 4538, Patchset 5: s.boundsCheckArrayIndex(left, i)
                    Keith Randall . unresolved

                    This needs to be left.X, to avoid re-evaluating the index.

                    Cuong Manh Le

                    Wait, the index belongs to `left`, not `left.X`. For example, with `a[i] = [0]int{}` case above, we have `left` is `a[i]`, `left.X` is `a`, and the index is `i`. So we do want to call `s.boundsCheckArrayIndex(a[i], i)`, so we won't re-evaluate `i`.

                    Keith Randall

                    Good point. `boundsCheckArrayIndex` is has this strange maybe-evaluates-part-of-it semantics.
                    I'd really like to do this somehow without such a strange function.

                    Open in Gerrit

                    Related details

                    Attention is currently required from:
                    • Cuong Manh Le
                    • Josh Bleecher Snyder
                    Submit Requirements:
                      • requirement is not satisfiedCode-Review
                      • requirement is not 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: master
                      Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
                      Gerrit-Change-Number: 775120
                      Gerrit-PatchSet: 6
                      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: Josh Bleecher Snyder <josh...@gmail.com>
                      Gerrit-Reviewer: Keith Randall <k...@golang.org>
                      Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
                      Gerrit-Attention: Cuong Manh Le <cuong.m...@gmail.com>
                      Gerrit-Comment-Date: Fri, 15 May 2026 19:02:16 +0000
                      Gerrit-HasComments: Yes
                      Gerrit-Has-Labels: No
                      unsatisfied_requirement
                      satisfied_requirement
                      open
                      diffy

                      Cuong Manh Le (Gerrit)

                      unread,
                      May 15, 2026, 5:06:51 PM (4 days ago) May 15
                      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
                      Attention needed from Cuong Manh Le and Josh Bleecher Snyder

                      Cuong Manh Le uploaded new patchset

                      Cuong Manh Le uploaded patch set #7 to this change.
                      Following approvals got outdated and were removed:

                      Related details

                      Attention is currently required from:
                      • Cuong Manh Le
                      • Josh Bleecher Snyder
                      Submit Requirements:
                        • requirement is not satisfiedCode-Review
                        • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
                        Gerrit-Change-Number: 775120
                        Gerrit-PatchSet: 7
                        unsatisfied_requirement
                        open
                        diffy

                        Cuong Manh Le (Gerrit)

                        unread,
                        May 15, 2026, 5:08:22 PM (4 days ago) May 15
                        to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
                        Attention needed from Josh Bleecher Snyder and Keith Randall

                        Cuong Manh Le voted and added 2 comments

                        Votes added by Cuong Manh Le

                        Auto-Submit+1
                        Commit-Queue+1

                        2 comments

                        File src/cmd/compile/internal/ssagen/ssa.go
                        Line 4532, Patchset 5 (Parent): s.boundsCheck(z, z, ssa.BoundsIndex, false)
                        Keith Randall . unresolved

                        Does this need a special case also?

                        ```
                        func f() [0]int { ... }
                        f()[i] = 3
                        ```
                        We still do want to evaluate `f()`.

                        Cuong Manh Le

                        Hmm, `f()[i]` is not addressable, so it even does not pass typechecker.

                        Further, even in case it passes, I believe order pass ensures `f()` was evaluated before we reach here, by re-written in roughly to:

                        ```
                        tmp = f()
                        tmp[i] = 3
                        ```

                        Keith Randall

                        I guess I meant something generically side-effecting in place of `f()`. For example,

                        var x *[0]int
                        (*x)[i] = 3

                        should nil panic, not bounds panic?

                        Cuong Manh Le

                        This code does nil panic, since it won't reach here. The condition of this block explicitly requires the `left.X` type is array:

                        ```
                        left.Op() == ir.OINDEX && left.(*ir.IndexExpr).X.Type().IsArray()
                        ```

                        In this case, it's a pointer to array.

                        Line 4538, Patchset 5: s.boundsCheckArrayIndex(left, i)
                        Keith Randall . unresolved

                        This needs to be left.X, to avoid re-evaluating the index.

                        Cuong Manh Le

                        Wait, the index belongs to `left`, not `left.X`. For example, with `a[i] = [0]int{}` case above, we have `left` is `a[i]`, `left.X` is `a`, and the index is `i`. So we do want to call `s.boundsCheckArrayIndex(a[i], i)`, so we won't re-evaluate `i`.

                        Keith Randall

                        Good point. `boundsCheckArrayIndex` is has this strange maybe-evaluates-part-of-it semantics.
                        I'd really like to do this somehow without such a strange function.

                        Cuong Manh Le

                        Oh, then I think we only need to call `boundsCheckArrayIndex` in case of `s.addr`, so we don't need the maybe-evaluates-part-of-it semantics anymore.

                        Open in Gerrit

                        Related details

                        Attention is currently required from:
                        • Josh Bleecher Snyder
                        • Keith Randall
                        Submit Requirements:
                        • requirement is not satisfiedCode-Review
                        • requirement is not 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: I2b97c81f779c8845f12f1ae519201c7af19cb497
                        Gerrit-Change-Number: 775120
                        Gerrit-PatchSet: 7
                        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: Josh Bleecher Snyder <josh...@gmail.com>
                        Gerrit-Reviewer: Keith Randall <k...@golang.org>
                        Gerrit-Attention: Keith Randall <k...@golang.org>
                        Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
                        Gerrit-Comment-Date: Fri, 15 May 2026 21:08:18 +0000
                        Gerrit-HasComments: Yes
                        Gerrit-Has-Labels: Yes
                        unsatisfied_requirement
                        open
                        diffy

                        Cuong Manh Le (Gerrit)

                        unread,
                        May 18, 2026, 11:05:52 PM (9 hours ago) May 18
                        to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, David Chase, Keith Randall, Josh Bleecher Snyder, golang-co...@googlegroups.com
                        Attention needed from Josh Bleecher Snyder and Keith Randall

                        Cuong Manh Le added 2 comments

                        File src/cmd/compile/internal/ssagen/ssa.go
                        Line 4532, Patchset 5 (Parent): s.boundsCheck(z, z, ssa.BoundsIndex, false)
                        Keith Randall . unresolved

                        Does this need a special case also?

                        ```
                        func f() [0]int { ... }
                        f()[i] = 3
                        ```
                        We still do want to evaluate `f()`.

                        Cuong Manh Le

                        Hmm, `f()[i]` is not addressable, so it even does not pass typechecker.

                        Further, even in case it passes, I believe order pass ensures `f()` was evaluated before we reach here, by re-written in roughly to:

                        ```
                        tmp = f()
                        tmp[i] = 3
                        ```

                        Keith Randall

                        I guess I meant something generically side-effecting in place of `f()`. For example,

                        var x *[0]int
                        (*x)[i] = 3

                        should nil panic, not bounds panic?

                        Cuong Manh Le

                        This code does nil panic, since it won't reach here. The condition of this block explicitly requires the `left.X` type is array:

                        ```
                        left.Op() == ir.OINDEX && left.(*ir.IndexExpr).X.Type().IsArray()
                        ```

                        In this case, it's a pointer to array.

                        Cuong Manh Le

                        Kindly ping @k...@golang.org?

                        Line 4538, Patchset 5: s.boundsCheckArrayIndex(left, i)
                        Keith Randall . resolved

                        This needs to be left.X, to avoid re-evaluating the index.

                        Cuong Manh Le

                        Wait, the index belongs to `left`, not `left.X`. For example, with `a[i] = [0]int{}` case above, we have `left` is `a[i]`, `left.X` is `a`, and the index is `i`. So we do want to call `s.boundsCheckArrayIndex(a[i], i)`, so we won't re-evaluate `i`.

                        Keith Randall

                        Good point. `boundsCheckArrayIndex` is has this strange maybe-evaluates-part-of-it semantics.
                        I'd really like to do this somehow without such a strange function.

                        Cuong Manh Le

                        Oh, then I think we only need to call `boundsCheckArrayIndex` in case of `s.addr`, so we don't need the maybe-evaluates-part-of-it semantics anymore.

                        Cuong Manh Le

                        Done

                        Open in Gerrit

                        Related details

                        Attention is currently required from:
                        • Josh Bleecher Snyder
                        • Keith Randall
                        Submit Requirements:
                          • requirement is not satisfiedCode-Review
                          • requirement is not 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: master
                          Gerrit-Change-Id: I2b97c81f779c8845f12f1ae519201c7af19cb497
                          Gerrit-Change-Number: 775120
                          Gerrit-PatchSet: 7
                          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: Josh Bleecher Snyder <josh...@gmail.com>
                          Gerrit-Reviewer: Keith Randall <k...@golang.org>
                          Gerrit-Attention: Keith Randall <k...@golang.org>
                          Gerrit-Attention: Josh Bleecher Snyder <josh...@gmail.com>
                          Gerrit-Comment-Date: Tue, 19 May 2026 03:05:43 +0000
                          Gerrit-HasComments: Yes
                          Gerrit-Has-Labels: No
                          unsatisfied_requirement
                          satisfied_requirement
                          open
                          diffy
                          Reply all
                          Reply to author
                          Forward
                          0 new messages