diff options
| author | Jonah Uellenberg <JonahUellenberg@gmail.com> | 2026-01-29 19:45:27 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-01-29 14:08:19 -0800 |
| commit | 14a4cb13e389d8dbc1ba3ba0097e208f1436a22a (patch) | |
| tree | cc5cc4779a33f574f50b52e80571590c7ca324b2 /test/loopbce.go | |
| parent | ee7a2119ac17ea2a6bbf12b4c8001bf39c388166 (diff) | |
| download | go-14a4cb13e389d8dbc1ba3ba0097e208f1436a22a.tar.xz | |
cmd/compile: make prove use non-equality in subtraction for a stronger bound
Given:
s := /* slice */
k := /* proved valid index in s (0 <= k < len(s)) */
v := s[k:]
len(v) >= 1, so v[0] needs no bounds check. However, for
len(v) = len(s) - k, we only checked if len(s) >= k and so could only
prove len(v) >= 0, thus the bounds check wasn't removed.
As far as I can tell these checks were commented out for performance,
but after benchmarking prove I see no difference.
Fixes: #76429
Change-Id: I39ba2a18cbabc0559924d4d226dcb99dbe9a06ed
GitHub-Last-Rev: 53f3344d261986cd021c8d7b8435ab89b5438b8f
GitHub-Pull-Request: golang/go#76609
Reviewed-on: https://go-review.googlesource.com/c/go/+/725100
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'test/loopbce.go')
| -rw-r--r-- | test/loopbce.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/test/loopbce.go b/test/loopbce.go index aabd56c682..ca09e7e7f7 100644 --- a/test/loopbce.go +++ b/test/loopbce.go @@ -17,8 +17,8 @@ func f0a(a []int) int { func f0b(a []int) int { x := 0 for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$" - b := a[i:] // ERROR "Proved IsSliceInBounds$" - x += b[0] + b := a[i:] // ERROR "Proved IsSliceInBounds$" "Proved slicemask not needed \(by limit\)$" + x += b[0] // ERROR "Proved IsInBounds$" } return x } @@ -417,7 +417,7 @@ func bce1() { func nobce2(a string) { for i := int64(0); i < int64(len(a)); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$" - useString(a[i:]) // ERROR "Proved IsSliceInBounds$" + useString(a[i:]) // ERROR "Proved IsSliceInBounds$" "Proved slicemask not needed \(by limit\)$" } for i := int64(0); i < int64(len(a))-31337; i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$" useString(a[i:]) // ERROR "Proved IsSliceInBounds$" "Proved slicemask not needed" |
