]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/prove.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / prove.go
index 3c19c513b65a61d2a69c4a3e14f7e600f6d82075..1aea2822912c2726625b247d531a4dd52dd550a2 100644 (file)
@@ -1,6 +1,7 @@
-// +build amd64
 // errorcheck -0 -d=ssa/prove/debug=1
 
+//go:build amd64
+
 // Copyright 2016 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.
@@ -498,7 +499,7 @@ func f19() (e int64, err error) {
        last := len(stack) - 1
        e = stack[last]
        // Buggy compiler prints "Disproved Leq64" for the next line.
-       stack = stack[:last] // ERROR "Proved IsSliceInBounds"
+       stack = stack[:last]
        return e, nil
 }
 
@@ -629,6 +630,22 @@ func trans3(a, b []int, i int) {
        _ = b[i] // ERROR "Proved IsInBounds$"
 }
 
+func trans4(b []byte, x int) {
+       // Issue #42603: slice len/cap transitive relations.
+       switch x {
+       case 0:
+               if len(b) < 20 {
+                       return
+               }
+               _ = b[:2] // ERROR "Proved IsSliceInBounds$"
+       case 1:
+               if len(b) < 40 {
+                       return
+               }
+               _ = b[:2] // ERROR "Proved IsSliceInBounds$"
+       }
+}
+
 // Derived from nat.cmp
 func natcmp(x, y []uint) (r int) {
        m := len(x)
@@ -670,8 +687,7 @@ func oforuntil(b []int) {
        i := 0
        if len(b) > i {
        top:
-               // TODO: remove the todo of next line once we complete the following optimization of CL 244579
-               // println(b[i]) // todo: ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
+               println(b[i]) // ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
                i++
                if i < len(b) {
                        goto top
@@ -720,9 +736,8 @@ func range1(b []int) {
 
 // range2 elements are larger, so they use the general form of a range loop.
 func range2(b [][32]int) {
-       for i, v := range b {
-               // TODO: remove the todo of next line once we complete the following optimization of CL 244579
-               b[i][0] = v[0] + 1 // todo: ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
+       for i, v := range b { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
+               b[i][0] = v[0] + 1 // ERROR "Proved IsInBounds$"
                if i < len(b) {    // ERROR "Proved Less64$"
                        println("x")
                }
@@ -779,7 +794,7 @@ func unrollUpExcl(a []int) int {
 func unrollUpIncl(a []int) int {
        var i, x int
        for i = 0; i <= len(a)-2; i += 2 { // ERROR "Induction variable: limits \[0,\?\], increment 2$"
-               x += a[i]
+               x += a[i] // ERROR "Proved IsInBounds$"
                x += a[i+1]
        }
        if i == len(a)-1 {
@@ -804,7 +819,7 @@ func unrollDownExcl0(a []int) int {
 // Induction variable in unrolled loop.
 func unrollDownExcl1(a []int) int {
        var i, x int
-       for i = len(a) - 1; i >= 1; i -= 2 { // ERROR "Induction variable: limits \[1,\?\], increment 2$"
+       for i = len(a) - 1; i >= 1; i -= 2 { // ERROR "Induction variable: limits \(0,\?\], increment 2$"
                x += a[i]   // ERROR "Proved IsInBounds$"
                x += a[i-1] // ERROR "Proved IsInBounds$"
        }
@@ -819,7 +834,7 @@ func unrollDownInclStep(a []int) int {
        var i, x int
        for i = len(a); i >= 2; i -= 2 { // ERROR "Induction variable: limits \[2,\?\], increment 2$"
                x += a[i-1] // ERROR "Proved IsInBounds$"
-               x += a[i-2]
+               x += a[i-2] // ERROR "Proved IsInBounds$"
        }
        if i == 1 {
                x += a[i-1]
@@ -999,7 +1014,7 @@ func sh64noopt(n int64) int64 {
 // opt, an earlier pass, has already replaced it.
 // The fix for this issue allows prove to zero a right shift that was added as
 // part of the less-than-optimal reqwrite. That change by prove then allows
-// lateopt to clean up all the unneccesary parts of the original division
+// lateopt to clean up all the unnecessary parts of the original division
 // replacement. See issue #36159.
 func divShiftClean(n int) int {
        if n < 0 {
@@ -1022,6 +1037,84 @@ func divShiftClean32(n int32) int32 {
        return n / int32(16) // ERROR "Proved Rsh32x64 shifts to zero"
 }
 
+// Bounds check elimination
+
+func sliceBCE1(p []string, h uint) string {
+       if len(p) == 0 {
+               return ""
+       }
+
+       i := h & uint(len(p)-1)
+       return p[i] // ERROR "Proved IsInBounds$"
+}
+
+func sliceBCE2(p []string, h int) string {
+       if len(p) == 0 {
+               return ""
+       }
+       i := h & (len(p) - 1)
+       return p[i] // ERROR "Proved IsInBounds$"
+}
+
+func and(p []byte) ([]byte, []byte) { // issue #52563
+       const blocksize = 16
+       fullBlocks := len(p) &^ (blocksize - 1)
+       blk := p[:fullBlocks] // ERROR "Proved IsSliceInBounds$"
+       rem := p[fullBlocks:] // ERROR "Proved IsSliceInBounds$"
+       return blk, rem
+}
+
+func rshu(x, y uint) int {
+       z := x >> y
+       if z <= x { // ERROR "Proved Leq64U$"
+               return 1
+       }
+       return 0
+}
+
+func divu(x, y uint) int {
+       z := x / y
+       if z <= x { // ERROR "Proved Leq64U$"
+               return 1
+       }
+       return 0
+}
+
+func modu1(x, y uint) int {
+       z := x % y
+       if z < y { // ERROR "Proved Less64U$"
+               return 1
+       }
+       return 0
+}
+
+func modu2(x, y uint) int {
+       z := x % y
+       if z <= x { // ERROR "Proved Leq64U$"
+               return 1
+       }
+       return 0
+}
+
+func issue57077(s []int) (left, right []int) {
+       middle := len(s) / 2
+       left = s[:middle] // ERROR "Proved IsSliceInBounds$"
+       right = s[middle:] // ERROR "Proved IsSliceInBounds$"
+       return
+}
+
+func issue51622(b []byte) int {
+       if len(b) >= 3 && b[len(b)-3] == '#' { // ERROR "Proved IsInBounds$"
+               return len(b)
+       }
+       return 0
+}
+
+func issue45928(x int) {
+       combinedFrac := x / (x | (1 << 31)) // ERROR "Proved Neq64$"
+       useInt(combinedFrac)
+}
+
 //go:noinline
 func useInt(a int) {
 }