aboutsummaryrefslogtreecommitdiff
path: root/test/prove.go
diff options
context:
space:
mode:
authorAlexandru Moșoi <brtzsnr@gmail.com>2016-04-02 10:29:11 +0200
committerAlexandru Moșoi <alexandru@mosoi.ro>2016-04-02 20:34:38 +0000
commit27ebc84716f19e1c5b21e3a14de3204d19f28499 (patch)
tree3664f42a60cd93d949325e22c67660323685589b /test/prove.go
parent72c1180852d5b059cd1e51d1db1956ea208b7f2f (diff)
downloadgo-27ebc84716f19e1c5b21e3a14de3204d19f28499.tar.gz
go-27ebc84716f19e1c5b21e3a14de3204d19f28499.zip
cmd/compile: handle non-negatives in prove
Handle this case: if 0 <= i && i < len(a) { use a[i] } Shaves about 5k from pkg/tools/linux_amd64/*. Change-Id: I6675ff49aa306b0d241b074c5738e448204cd981 Reviewed-on: https://go-review.googlesource.com/21431 Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'test/prove.go')
-rw-r--r--test/prove.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/test/prove.go b/test/prove.go
index 4fc1d674d8..a78adf03dc 100644
--- a/test/prove.go
+++ b/test/prove.go
@@ -29,11 +29,30 @@ func f1(a []int) int {
}
func f1b(a []int, i int, j uint) int {
- if i >= 0 && i < len(a) { // TODO: handle this case
- return a[i]
+ if i >= 0 && i < len(a) {
+ return a[i] // ERROR "Proved non-negative bounds IsInBounds$"
+ }
+ if i >= 10 && i < len(a) {
+ return a[i] // ERROR "Proved non-negative bounds IsInBounds$"
+ }
+ if i >= 10 && i < len(a) {
+ return a[i] // ERROR "Proved non-negative bounds IsInBounds$"
+ }
+ if i >= 10 && i < len(a) { // todo: handle this case
+ return a[i-10]
}
if j < uint(len(a)) {
- return a[j] // ERROR "Proved IsInBounds"
+ return a[j] // ERROR "Proved IsInBounds$"
+ }
+ return 0
+}
+
+func f1c(a []int, i int64) int {
+ c := uint64(math.MaxInt64 + 10) // overflows int
+ d := int64(c)
+ if i >= d && i < int64(len(a)) {
+ // d overflows, should not be handled.
+ return a[i]
}
return 0
}