]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix off-by-one error in prove pass
authorKeith Randall <khr@golang.org>
Fri, 9 Aug 2024 17:59:43 +0000 (10:59 -0700)
committerKeith Randall <khr@golang.org>
Fri, 9 Aug 2024 20:14:40 +0000 (20:14 +0000)
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 <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/ssa/prove.go
test/fixedbugs/issue68809.go [new file with mode: 0644]

index c2ac6ca40f44d8b0f75e5382815f6c1a9c9ae84d..d563204565aaaf5c45e3b5614a5d3f6567f4e1d7 100644 (file)
@@ -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 (file)
index 0000000..67afda6
--- /dev/null
@@ -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")
+       }
+}