From: Keith Randall Date: Fri, 9 Aug 2024 17:59:43 +0000 (-0700) Subject: cmd/compile: fix off-by-one error in prove pass X-Git-Tag: go1.24rc1~1230 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f259e4c916bcde5221dca99ce7d77095a21b9801;p=gostls13.git cmd/compile: fix off-by-one error in prove pass I think I introduced #68809 when rewriting the prove pass, by introducing an off-by-one error here: https://go-review.googlesource.com/c/go/+/599096/5/src/cmd/compile/internal/ssa/prove.go lines 872-874. The min++ is already handled in one of the two following cases with the (r&eq==0) condition. Move the min++ to just the other case. Fixes #68809 Change-Id: Iffae99e29219c94aaf584cd7ae247289fa604a00 Reviewed-on: https://go-review.googlesource.com/c/go/+/604100 Reviewed-by: Keith Randall Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index c2ac6ca40f..d563204565 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -1059,9 +1059,6 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) { // We know that either x>min OR x<=max. factsTable cannot record OR conditions, // so let's see if we can already prove that one of them is false, in which case // the other must be true - if r == gt { - min++ - } l := ft.limits[x.ID] if l.max <= min { if r&eq == 0 || l.max < min { @@ -1070,6 +1067,9 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) { } } else if l.min > max { // x<=max is impossible, so it must be x>min + if r == gt { + min++ + } ft.signedMin(x, min) } } diff --git a/test/fixedbugs/issue68809.go b/test/fixedbugs/issue68809.go new file mode 100644 index 0000000000..67afda6708 --- /dev/null +++ b/test/fixedbugs/issue68809.go @@ -0,0 +1,19 @@ +// run + +// Copyright 2024 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. + +package main + +func main() { + cnt := 0 + for i := 1; i <= 11; i++ { + if i-6 > 4 { + cnt++ + } + } + if cnt != 1 { + panic("bad") + } +}