/ go Public
cmd/compile: teach prove about incrementing, len, and overflow #36346
Issues related to the Go compiler and/or runtime.
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
I have some hot code that looks approximately like this:
The generated code has a bounds check on every iteration. This is because
imight be negative. We can rule that out up front:
This could should be able to go without a bounds check.
icannot be negative at the beginning. In order to become negative, it must overflow. However, it cannot overflow: It is being incremented, so it must reach
len(a)before overflowing, in which case we exit the loop before evaluating
(I actually know a priori in my code that
iis not negative; I'd be tempted to use #30582 here. I could also switch to
ibeing a uint, which does remove the bounds check, but it makes other things in the real code a bit awkward.)
I don't know how hard it is to teach prove about this case.
cc @zdjones @rasky @randall77
The text was updated successfully, but these errors were encountered: