Skip to content

cmd/compile: more missing bounds checks on zero-sized things #79236

Closed

Description

@josharian

Go version

tip (d5ebe81)

Output of go env in your module/workspace:

-

What did you do?

Run https://go.dev/play/p/9BKvLvDAspF

package main

import "fmt"

//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 {
			fmt.Printf("%s: got panic: %v\n", name, r)
			return
		}
		fmt.Printf("%s: no panic (bug)\n", name)
	}()
	f()
}

func main() {
	wantPanic("a1", func() { a1(5) })
	wantPanic("a2", func() { _ = a2(5) })
	wantPanic("a3", func() { a3(5) })
}

What did you see happen?

no panics

What did you expect to see?

panics

Similar to #79197; sorry I missed these then.

Introduced, I believe, by 0886e65.

cc @cuonglm @randall77

Activity

  1. changed the title [-]cmd/compile[/-] [+]cmd/compile: more missing bounds checks on zero-sized things[/+] on May 6, 2026
  2. added
    BugReportIssues describing a possible bug in the Go implementation.
    on May 6, 2026
  3. cuonglm commented on May 7, 2026

    @cuonglm
  4. cuonglm commented on May 7, 2026

    @cuonglm
  5. self-assigned this
    on May 7, 2026
  6. gopherbot commented on May 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/775120 mentions this issue: cmd/compile: recursively insert bounds checks for zero-sized arrays

  7. added this to the Go1.27 milestone on May 20, 2026
  8. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on May 20, 2026
  9. added
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    and removed
    NeedsFixThe path to resolution is known, but the work has not been done.
    on May 20, 2026
  10. added a commit that references this issue on May 26, 2026
    e28acf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.release-blocker

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions