1 // errorcheck -0 -d=append,slice,ssa/prove/debug=1
3 // Copyright 2015 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Check optimization results for append and slicing.
11 func a1(x []int, y int) []int {
12 x = append(x, y) // ERROR "append: len-only update \(in local slice\)$"
16 func a2(x []int, y int) []int {
20 func a3(x *[]int, y int) {
21 *x = append(*x, y) // ERROR "append: len-only update$"
24 // s1_if_false_then_anything
25 func s1_if_false_then_anything(x **[]int, xs **string, i, j int) {
28 println(z) // if we get here, then we have proven that i==i+1 (this cannot happen, but the program is still being analyzed...)
30 zs := (**xs)[0:i] // since i=i+1 is proven, i+1 is "in bounds", ha-ha
31 zs = zs[i : i+1] // ERROR "Proved boolean IsSliceInBounds$"
35 func s1(x **[]int, xs **string, i, j int) {
38 z = (**x)[2:len(**x)] // ERROR "Proved boolean IsSliceInBounds$"
39 z = (**x)[2:cap(**x)] // ERROR "Proved IsSliceInBounds$"
40 z = (**x)[i:i] // -ERROR "Proved IsSliceInBounds"
41 z = (**x)[1:i:i] // ERROR "Proved boolean IsSliceInBounds$"
43 z = (**x)[i:0:j] // ERROR "Disproved IsSliceInBounds$"
44 z = (**x)[0:i:j] // ERROR "Proved boolean IsSliceInBounds$"
45 z = (**x)[0:] // ERROR "slice: omit slice operation$"
46 z = (**x)[2:8] // ERROR "Proved slicemask not needed$"
50 z = (**x)[2:i:8] // ERROR "Disproved IsSliceInBounds$" "Proved IsSliceInBounds$"
51 z = (**x)[i:2:i] // ERROR "Proved IsSliceInBounds$" "Proved boolean IsSliceInBounds$"
53 z = z[0:i] // ERROR "Proved boolean IsSliceInBounds"
55 z = z[i : i+1] // ERROR "Proved boolean IsSliceInBounds$"
61 zs = (**xs)[2:len(**xs)] // ERROR "Proved IsSliceInBounds$" "Proved boolean IsSliceInBounds$"
62 zs = (**xs)[i:i] // -ERROR "Proved boolean IsSliceInBounds"
63 zs = (**xs)[0:] // ERROR "slice: omit slice operation$"
65 zs = (**xs)[2:2] // ERROR "Proved boolean IsSliceInBounds$"
66 zs = (**xs)[0:i] // ERROR "Proved boolean IsSliceInBounds$"
68 zs = zs[0:i] // See s1_if_false_then_anything above to explain the counterfactual bounds check result below
69 zs = zs[i : i+1] // ERROR "Proved boolean IsSliceInBounds$"