cmd/compile: prove pass unable to eliminate bounds check when a variable is assigned from len #32515
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?What did you do?
Consider -
The compiler is unable to prove that
buf[i]
will be always in range. But it should be, because n is positive, and len(buf) = n+1.A hint of
_ = buf[n]
or alternatively, changing the bounds from<= n
to< len(buf)
fixes it.This actually came from a real-world code from my levenshtein library. See agnivade/levenshtein@1e1f2ae#diff-12f7126b3ca34e44fe76e482d22fba93R46.
What did you expect to see?
No bounds check
What did you see instead?
Bounds check
Apologies if this is already filed somewhere else. I did not see it in my search.
@zdjones @rasky
Also @mvdan (we had a conversation on this on slack)
The text was updated successfully, but these errors were encountered: