aboutsummaryrefslogtreecommitdiff
path: root/test/sliceopt.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2016-10-19 11:47:52 -0400
committerDavid Chase <drchase@google.com>2016-10-20 23:50:19 +0000
commit0f29942489409ccd81619b5f82fce9c7de18165f (patch)
treea4212d76f74d68d095c89f65f89dc5fcfde84975 /test/sliceopt.go
parentc9517b1ffe7c99a3fd2a748fab51645bd674ad75 (diff)
downloadgo-0f29942489409ccd81619b5f82fce9c7de18165f.tar.gz
go-0f29942489409ccd81619b5f82fce9c7de18165f.zip
cmd/compile: Repurpose old sliceopt.go for prove phase.
Adapt old test for prove's bounds check elimination. Added missing rule to generic rules that lead to differences between 32 and 64 bit platforms on sliceopt test. Added debugging to prove.go that was helpful-to-necessary to discover that missing rule. Lowered debugging level on prove.go from 3 to 1; no idea why it was previously 3. Change-Id: I09de206aeb2fced9f2796efe2bfd4a59927eda0c Reviewed-on: https://go-review.googlesource.com/23290 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/sliceopt.go')
-rw-r--r--test/sliceopt.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/sliceopt.go b/test/sliceopt.go
new file mode 100644
index 0000000000..17959e9326
--- /dev/null
+++ b/test/sliceopt.go
@@ -0,0 +1,70 @@
+// errorcheck -0 -d=append,slice,ssa/prove/debug=1
+
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Check optimization results for append and slicing.
+
+package main
+
+func a1(x []int, y int) []int {
+ x = append(x, y) // ERROR "append: len-only update \(in local slice\)$"
+ return x
+}
+
+func a2(x []int, y int) []int {
+ return append(x, y)
+}
+
+func a3(x *[]int, y int) {
+ *x = append(*x, y) // ERROR "append: len-only update$"
+}
+
+// s1_if_false_then_anything
+func s1_if_false_then_anything(x **[]int, xs **string, i, j int) {
+ z := (**x)[0:i]
+ z = z[i : i+1]
+ println(z) // if we get here, then we have proven that i==i+1 (this cannot happen, but the program is still being analyzed...)
+
+ zs := (**xs)[0:i] // since i=i+1 is proven, i+1 is "in bounds", ha-ha
+ zs = zs[i : i+1] // ERROR "Proved boolean IsSliceInBounds$"
+ println(zs)
+}
+
+func s1(x **[]int, xs **string, i, j int) {
+ var z []int
+ z = (**x)[2:]
+ z = (**x)[2:len(**x)] // ERROR "Proved boolean IsSliceInBounds$"
+ z = (**x)[2:cap(**x)] // ERROR "Proved IsSliceInBounds$"
+ z = (**x)[i:i] // -ERROR "Proved IsSliceInBounds"
+ z = (**x)[1:i:i] // ERROR "Proved boolean IsSliceInBounds$"
+ z = (**x)[i:j:0]
+ z = (**x)[i:0:j] // ERROR "Disproved IsSliceInBounds$"
+ z = (**x)[0:i:j] // ERROR "Proved boolean IsSliceInBounds$"
+ z = (**x)[0:] // ERROR "slice: omit slice operation$"
+ z = (**x)[2:8] // ERROR "Disproved Eq(32|64)$"
+ z = (**x)[2:2] // ERROR "Disproved Eq(32|64)$" "Proved boolean IsSliceInBounds$"
+ z = (**x)[0:i] // ERROR "Proved boolean IsSliceInBounds$"
+ z = (**x)[2:i:8] // ERROR "Disproved IsSliceInBounds$" "Proved IsSliceInBounds$" "Proved boolean IsSliceInBounds$"
+ z = (**x)[i:2:i] // ERROR "Proved IsSliceInBounds$" "Proved boolean IsSliceInBounds$"
+
+ z = z[0:i] // ERROR "Proved boolean IsSliceInBounds"
+ z = z[0:i : i+1]
+ z = z[i : i+1] // ERROR "Proved boolean IsSliceInBounds$"
+
+ println(z)
+
+ var zs string
+ zs = (**xs)[2:]
+ zs = (**xs)[2:len(**xs)] // ERROR "Proved IsSliceInBounds$" "Proved boolean IsSliceInBounds$"
+ zs = (**xs)[i:i] // -ERROR "Proved boolean IsSliceInBounds"
+ zs = (**xs)[0:] // ERROR "slice: omit slice operation$"
+ zs = (**xs)[2:8]
+ zs = (**xs)[2:2] // ERROR "Proved boolean IsSliceInBounds$"
+ zs = (**xs)[0:i] // ERROR "Proved boolean IsSliceInBounds$"
+
+ zs = zs[0:i] // See s1_if_false_then_anything above to explain the counterfactual bounds check result below
+ zs = zs[i : i+1] // ERROR "Proved boolean IsSliceInBounds$"
+ println(zs)
+}