aboutsummaryrefslogtreecommitdiff
path: root/test/loopbce.go
diff options
context:
space:
mode:
authorAlexandru Moșoi <mosoi@google.com>2016-04-01 15:09:19 +0200
committerAlexandru Moșoi <alexandru@mosoi.ro>2016-04-11 16:01:22 +0000
commit6c6089b3fdba9eb0cff863a03074dbac47c92f63 (patch)
tree8d4eacf7fc80504db1a2bf1468b3192060ce1dcd /test/loopbce.go
parent00681eec6aec03b8b2822c9220fba27c18923c01 (diff)
downloadgo-6c6089b3fdba9eb0cff863a03074dbac47c92f63.tar.gz
go-6c6089b3fdba9eb0cff863a03074dbac47c92f63.zip
cmd/compile: bce when max and limit are consts
Removes 49 more bound checks in make.bash. For example: var a[100]int for i := 0; i < 50; i++ { use a[i+25] } Change-Id: I85e0130ee5d07f0ece9b17044bba1a2047414ce7 Reviewed-on: https://go-review.googlesource.com/21379 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Alexandru Moșoi <alexandru@mosoi.ro> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/loopbce.go')
-rw-r--r--test/loopbce.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/loopbce.go b/test/loopbce.go
index eb44092705..ea195217e6 100644
--- a/test/loopbce.go
+++ b/test/loopbce.go
@@ -139,6 +139,70 @@ func h2(a []byte) {
}
}
+func k0(a [100]int) [100]int {
+ for i := 10; i < 90; i++ { // ERROR "Induction variable with minimum 10 and increment 1$"
+ a[i-11] = i
+ a[i-10] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 80$"
+ a[i-5] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 85$"
+ a[i] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 90$"
+ a[i+5] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 95$"
+ a[i+10] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 100$"
+ a[i+11] = i
+ }
+ return a
+}
+
+func k1(a [100]int) [100]int {
+ for i := 10; i < 90; i++ { // ERROR "Induction variable with minimum 10 and increment 1$"
+ useSlice(a[:i-11])
+ useSlice(a[:i-10]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 80$"
+ useSlice(a[:i-5]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 85$"
+ useSlice(a[:i]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 90$"
+ useSlice(a[:i+5]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 95$"
+ useSlice(a[:i+10]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 100$"
+ useSlice(a[:i+11]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 101$"
+
+ }
+ return a
+}
+
+func k2(a [100]int) [100]int {
+ for i := 10; i < 90; i++ { // ERROR "Induction variable with minimum 10 and increment 1$"
+ useSlice(a[i-11:])
+ useSlice(a[i-10:]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 80$"
+ useSlice(a[i-5:]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 85$"
+ useSlice(a[i:]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 90$"
+ useSlice(a[i+5:]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 95$"
+ useSlice(a[i+10:]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 100$"
+ useSlice(a[i+11:]) // ERROR "Found redundant \(IsSliceInBounds ind 100\), ind < 101$"
+ }
+ return a
+}
+
+func k3(a [100]int) [100]int {
+ for i := -10; i < 90; i++ { // ERROR "Induction variable with minimum -10 and increment 1$"
+ a[i+10] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 100$"
+ }
+ return a
+}
+
+func k4(a [100]int) [100]int {
+ min := (-1) << 63
+ for i := min; i < min+50; i++ { // ERROR "Induction variable with minimum -9223372036854775808 and increment 1$"
+ a[i-min] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 50$"
+ }
+ return a
+}
+
+func k5(a [100]int) [100]int {
+ max := (1 << 63) - 1
+ for i := max - 50; i < max; i++ { // ERROR "Induction variable with minimum 9223372036854775757 and increment 1$"
+ a[i-max+50] = i
+ a[i-(max-70)] = i // ERROR "Found redundant \(IsInBounds ind 100\), ind < 70$"
+ }
+ return a
+}
+
func nobce1() {
// tests overflow of max-min
a := int64(9223372036854774057)
@@ -168,9 +232,22 @@ func nobce2(a string) {
}
}
+func nobce3(a [100]int64) [100]int64 {
+ min := int64((-1) << 63)
+ max := int64((1 << 63) - 1)
+ for i := min; i < max; i++ { // ERROR "Induction variable with minimum -9223372036854775808 and increment 1$"
+ a[i] = i
+ }
+ return a
+}
+
//go:noinline
func useString(a string) {
}
+//go:noinline
+func useSlice(a []int) {
+}
+
func main() {
}