-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: The bounds check can be removed in u%uint(x) for all x != 0 && x <= len(slice). #15079
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
Labels
Comments
I would assert that this bug is about all this arithmetic not constant-folding away to nothing. |
Note: Wrt issue title: The bounds check can be removed in u%uint(x) for all x != 0 && x <= len(slice). |
Note that in general, if i is a signed type, slice[i % len(slice)]
still need to do bound check against the i < 0 case because
Go specifies that if i < 0, i % len(slice) < 0.
|
Also, len(slice) can be 0 which means division by zero. |
CL https://golang.org/cl/21501 mentions this issue. |
CL https://golang.org/cl/21502 mentions this issue. |
gopherbot
pushed a commit
that referenced
this issue
Apr 4, 2016
In b we only need the division by 0 check. func b(i uint, v []byte) byte { return v[i%uint(len(v))] } Updates #15079. Change-Id: Ic7491e677dd57cd6ba577efbce576dbb6e023cbd Reviewed-on: https://go-review.googlesource.com/21502 Run-TryBot: Alexandru Moșoi <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Ahmed Waheed <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Please answer these questions before submitting your issue. Thanks!
go version
)?go version devel +29267c2 2016-04-03 01:50:04 +0000 linux/amd64
go env
)?http://play.golang.org/p/gWCa1r06CI
bb
(and maybeaa
)'s bounds checking removedI could've sworn there was a bug about this, but I can't find it
The text was updated successfully, but these errors were encountered: