Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/cmd/compile/internal/ssa/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2162,24 +2162,22 @@ func (ft *factsTable) detectSubRelations(v *Value) {
return // x-y might overflow
}

// Subtracting a positive number only makes
// things smaller.
if yLim.min >= 0 {
// Subtracting a positive non-zero number only makes
// things smaller. If it's positive or zero, it might
// also do nothing (x-0 == v).
if yLim.min > 0 {
ft.update(v.Block, v, x, signed, lt)
} else if yLim.min == 0 {
ft.update(v.Block, v, x, signed, lt|eq)
// TODO: is this worth it?
//if yLim.min > 0 {
// ft.update(v.Block, v, x, signed, lt)
//}
}

// Subtracting a number from a bigger one
// can't go below 0.
if ft.orderS.OrderedOrEqual(y, x) {
// can't go below 1. If the numbers might be
// equal, then it can't go below 0.
if ft.orderS.Ordered(y, x) {
ft.signedMin(v, 1)
} else if ft.orderS.OrderedOrEqual(y, x) {
ft.setNonNegative(v)
// TODO: is this worth it?
//if ft.orderS.Ordered(y, x) {
// ft.signedMin(v, 1)
//}
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/loopbce.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func f0a(a []int) int {
func f0b(a []int) int {
x := 0
for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
b := a[i:] // ERROR "Proved IsSliceInBounds$"
x += b[0]
b := a[i:] // ERROR "Proved IsSliceInBounds$" "Proved slicemask not needed \(by limit\)$"
x += b[0] // ERROR "Proved IsInBounds$"
}
return x
}
Expand Down Expand Up @@ -417,7 +417,7 @@ func bce1() {

func nobce2(a string) {
for i := int64(0); i < int64(len(a)); i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
useString(a[i:]) // ERROR "Proved IsSliceInBounds$"
useString(a[i:]) // ERROR "Proved IsSliceInBounds$" "Proved slicemask not needed \(by limit\)$"
}
for i := int64(0); i < int64(len(a))-31337; i++ { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
useString(a[i:]) // ERROR "Proved IsSliceInBounds$" "Proved slicemask not needed"
Expand Down
10 changes: 9 additions & 1 deletion test/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,7 @@ func swapbound(v []int) {
for i := 0; i < len(v)/2; i++ { // ERROR "Proved Div64 is unsigned|Induction variable"
v[i], // ERROR "Proved IsInBounds"
v[len(v)-1-i] = // ERROR "Proved IsInBounds"
v[len(v)-1-i],
v[len(v)-1-i], // ERROR "Proved IsInBounds"
v[i] // ERROR "Proved IsInBounds"
}
}
Expand Down Expand Up @@ -2718,6 +2718,14 @@ func detectStringLenRelation(s string) bool {
return false
}

func issue76429(s []byte, k int) byte {
if k < 0 || k >= len(s) {
return 0
}
s = s[k:] // ERROR "Proved IsSliceInBounds" "Proved slicemask not needed"
return s[0] // ERROR "Proved IsInBounds"
}

//go:noinline
func prove(x int) {
}
Expand Down