aboutsummaryrefslogtreecommitdiff
path: root/test/prove.go
diff options
context:
space:
mode:
authorGiovanni Bajo <rasky@develer.com>2019-09-22 15:39:16 +0200
committerGiovanni Bajo <rasky@develer.com>2019-09-26 18:27:38 +0000
commit87e2b34f7bdd997b09f926ccbef6bfd2794d8e2a (patch)
treeb5086596b858e48981f37f2babb9d4700a0e2492 /test/prove.go
parent08165932f77aacf82a1e41138e7650e5992b98f7 (diff)
downloadgo-87e2b34f7bdd997b09f926ccbef6bfd2794d8e2a.tar.gz
go-87e2b34f7bdd997b09f926ccbef6bfd2794d8e2a.zip
cmd/compile: in prove, learn facts from OpSliceMake
Now that OpSliceMake is called by runtime.makeslice callers, prove can see and record the actual length and cap of each slice being constructed. This small patch is enough to remove 260 additional bound checks from cmd+std. Thanks to Martin Möhrmann for pointing me to CL141822 that I had missed. Updates #24660 Change-Id: I14556850f285392051f3f07d13b456b608b64eb9 Reviewed-on: https://go-review.googlesource.com/c/go/+/196784 Run-TryBot: Giovanni Bajo <rasky@develer.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test/prove.go')
-rw-r--r--test/prove.go40
1 files changed, 32 insertions, 8 deletions
diff --git a/test/prove.go b/test/prove.go
index 7643031c62..6629982ba8 100644
--- a/test/prove.go
+++ b/test/prove.go
@@ -678,6 +678,30 @@ func oforuntil(b []int) {
}
}
+func atexit(foobar []func()) {
+ for i := len(foobar) - 1; i >= 0; i-- { // ERROR "Induction variable: limits \[0,\?\], increment 1"
+ f := foobar[i]
+ foobar = foobar[:i] // ERROR "IsSliceInBounds"
+ f()
+ }
+}
+
+func make1(n int) []int {
+ s := make([]int, n)
+ for i := 0; i < n; i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1"
+ s[i] = 1 // ERROR "Proved IsInBounds$"
+ }
+ return s
+}
+
+func make2(n int) []int {
+ s := make([]int, n)
+ for i := range s { // ERROR "Induction variable: limits \[0,\?\), increment 1"
+ s[i] = 1 // ERROR "Proved IsInBounds$"
+ }
+ return s
+}
+
// The range tests below test the index variable of range loops.
// range1 compiles to the "efficiently indexable" form of a range loop.
@@ -862,13 +886,13 @@ func signExtNto64(x []int, j8 int8, j16 int16, j32 int32) int {
return 0
}
if j8 >= 0 && j8 < 22 {
- return x[j8] // ERROR "Proved IsInBounds$"
+ return x[j8] // ERROR "Proved IsInBounds$"
}
if j16 >= 0 && j16 < 22 {
- return x[j16] // ERROR "Proved IsInBounds$"
+ return x[j16] // ERROR "Proved IsInBounds$"
}
if j32 >= 0 && j32 < 22 {
- return x[j32] // ERROR "Proved IsInBounds$"
+ return x[j32] // ERROR "Proved IsInBounds$"
}
return 0
}
@@ -878,13 +902,13 @@ func zeroExtNto64(x []int, j8 uint8, j16 uint16, j32 uint32) int {
return 0
}
if j8 >= 0 && j8 < 22 {
- return x[j8] // ERROR "Proved IsInBounds$"
+ return x[j8] // ERROR "Proved IsInBounds$"
}
if j16 >= 0 && j16 < 22 {
- return x[j16] // ERROR "Proved IsInBounds$"
+ return x[j16] // ERROR "Proved IsInBounds$"
}
if j32 >= 0 && j32 < 22 {
- return x[j32] // ERROR "Proved IsInBounds$"
+ return x[j32] // ERROR "Proved IsInBounds$"
}
return 0
}
@@ -894,7 +918,7 @@ func signExt32to64Fence(x []int, j int32) int {
if x[j] != 0 {
return 1
}
- if j > 0 && x[j-1] != 0 { // ERROR "Proved IsInBounds$"
+ if j > 0 && x[j-1] != 0 { // ERROR "Proved IsInBounds$"
return 1
}
return 0
@@ -904,7 +928,7 @@ func zeroExt32to64Fence(x []int, j uint32) int {
if x[j] != 0 {
return 1
}
- if j > 0 && x[j-1] != 0 { // ERROR "Proved IsInBounds$"
+ if j > 0 && x[j-1] != 0 { // ERROR "Proved IsInBounds$"
return 1
}
return 0