-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: teach BCE about copy return value #16833
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
Comments
Also, we know |
Probably related: #19126 |
Just bumped into this again. cc @zdjones |
I was just about to file a duplicate issue having run into this myself. None of the following bounds checks are eliminated: package bce
func copyByte1(dst, src []byte) []byte {
n := copy(dst, src)
return dst[n:]
}
func copyByte2(dst, src []byte) []byte {
n := copy(dst, src)
return src[n:]
}
func copyString(dst []byte, src string) string {
n := copy(dst, src)
return src[n:]
} Though in each case they could be. |
Just hit this in some crypto code.
|
Change https://go.dev/cl/622240 mentions this issue: |
compiles to
Observe the bounds check on
_ = s[x:]
. In comparison, using_ = s[len(s):]
doesn't generate a bounds check. But the semantics ofcopy
guarantee thatx <= len(s)
. So we should be able to eliminate the check.See CL 27460 for a concrete instance in the runtime.
cc @brtzsnr @bradfitz
The text was updated successfully, but these errors were encountered: