Skip to content

cmd/compile: bounds check elimination unaware of copy return value #70063

@FiloSottile

Description

@FiloSottile
go version devel go1.24-140308837f Mon Oct 21 15:30:47 2024 +0200 darwin/arm64

The return value of copy is guaranteed to be <= len(x) for x being both the arguments, so the following function shouldn't have bounds checks.

func foo(a, b []byte) {
	n := copy(a, b)
	_ = a[n:] // bounds check!
	_ = b[n:] // bounds check!
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions