aboutsummaryrefslogtreecommitdiff
path: root/test/prove.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-11-27 11:43:08 -0800
committerKeith Randall <khr@golang.org>2017-02-02 17:45:58 +0000
commit73f92f9b0405e98427bbb445f24cffb5d3c4d01b (patch)
tree05df0d7b52dc6316d6b939d8d817b2f91e8d4595 /test/prove.go
parent6317f92f6e51f679712deec6094c6b5fc2948a5b (diff)
downloadgo-73f92f9b0405e98427bbb445f24cffb5d3c4d01b.tar.gz
go-73f92f9b0405e98427bbb445f24cffb5d3c4d01b.zip
cmd/compile: use len(s)<=cap(s) to remove more bounds checks
When we discover a relation x <= len(s), also discover the relation x <= cap(s). That way, in situations like: a := s[x:] // tests 0 <= x <= len(s) b := s[:x] // tests 0 <= x <= cap(s) the second check can be eliminated. Fixes #16813 Change-Id: Ifc037920b6955e43bac1a1eaf6bac63a89cfbd44 Reviewed-on: https://go-review.googlesource.com/33633 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alexandru Moșoi <alexandru@mosoi.ro> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/prove.go')
-rw-r--r--test/prove.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/prove.go b/test/prove.go
index 9ef8949e1c..5f4de604c6 100644
--- a/test/prove.go
+++ b/test/prove.go
@@ -451,6 +451,18 @@ func f14(p, q *int, a []int) {
useInt(a[i2+j]) // ERROR "Proved boolean IsInBounds$"
}
+func f15(s []int, x int) {
+ useSlice(s[x:])
+ useSlice(s[:x]) // ERROR "Proved IsSliceInBounds$"
+}
+
+func f16(s []int) []int {
+ if len(s) >= 10 {
+ return s[:10] // ERROR "Proved non-negative bounds IsSliceInBounds$"
+ }
+ return nil
+}
+
//go:noinline
func useInt(a int) {
}