aboutsummaryrefslogtreecommitdiff
path: root/test/prove.go
diff options
context:
space:
mode:
authorzdjones <zachj1@gmail.com>2019-03-30 17:28:05 +0000
committerGiovanni Bajo <rasky@develer.com>2019-03-30 23:22:02 +0000
commit2d41444ad0c1540f064695a9a4678dda6c0d2a51 (patch)
tree5846a8b857ac7525e736cd26e94c207defbd7bdc /test/prove.go
parent637f34fee0dd3533e2d9eead6fd6e1dc25eb8d26 (diff)
downloadgo-2d41444ad0c1540f064695a9a4678dda6c0d2a51.tar.gz
go-2d41444ad0c1540f064695a9a4678dda6c0d2a51.zip
cmd/compile: make prove learn index >= 0 from successful bounds checks
When branching at a bounds check for indexing or slicing ops, prove currently only learns from the upper bound. On the positive branch, we currently learn i < len(a) (or i <= len(a)) in both the signed and unsigned domains. This CL makes prove also learn from the lower bound. Specifically, on the positive branch from index or slicing ops, prove will now ALSO learn i >= 0 in the signed domain (this fact is of no value in the unsigned domain). The substantive change itself is only an additional call to addRestrictions, though I've also inverted the nested switch statements around that call for the sake of clarity. This CL removes 92 bounds checks from std and cmd. It passes all tests and shows no deltas on compilecmp. Fixes #28885 Change-Id: I13eccc36e640eb599fa6dc5aa3be3c7d7abd2d9e Reviewed-on: https://go-review.googlesource.com/c/go/+/170121 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Giovanni Bajo <rasky@develer.com>
Diffstat (limited to 'test/prove.go')
-rw-r--r--test/prove.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/prove.go b/test/prove.go
index 39b23c5e0a..6e92b9eec2 100644
--- a/test/prove.go
+++ b/test/prove.go
@@ -726,6 +726,16 @@ func signHint2(b []byte, n int) {
}
}
+// indexGT0 tests whether prove learns int index >= 0 from bounds check.
+func indexGT0(b []byte, n int) {
+ _ = b[n]
+ _ = b[25]
+
+ for i := n; i <= 25; i++ { // ERROR "Induction variable: limits \[\?,25\], increment 1$"
+ b[i] = 123 // ERROR "Proved IsInBounds$"
+ }
+}
+
// Induction variable in unrolled loop.
func unrollUpExcl(a []int) int {
var i, x int