Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
FiloSottile opened this issue Oct 26, 2024 · 2 comments
Closed

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

FiloSottile opened this issue Oct 26, 2024 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance

Comments

@FiloSottile
Copy link
Contributor

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!
}
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 26, 2024
@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@FiloSottile
Copy link
Contributor Author

Duplicate of #16833.

@FiloSottile FiloSottile closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

3 participants