aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2025-03-09 14:37:30 +0100
committerJorropo <jorropo.pgm@gmail.com>2025-03-11 19:51:31 -0700
commitd2842229fce01f8df04bc141291ec4fefb5d4bfc (patch)
treee3f9bed32493750780a43099dfa4755f8fade044 /test
parentbcd0ebbd2abcd3e2e876862f287c46a2de56eaab (diff)
downloadgo-d2842229fce01f8df04bc141291ec4fefb5d4bfc.tar.xz
cmd/compile: compute min's & max's limits from argument's limits inside flowLimit
Updates #68857 Change-Id: Ied07e656bba42f3b1b5f9b9f5442806aa2e7959b Reviewed-on: https://go-review.googlesource.com/c/go/+/656157 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/prove.go311
1 files changed, 311 insertions, 0 deletions
diff --git a/test/prove.go b/test/prove.go
index 908b05c7fa..9c829be459 100644
--- a/test/prove.go
+++ b/test/prove.go
@@ -1691,6 +1691,317 @@ func phiMin(a, b []byte) {
_ = b[:y] // ERROR "Proved IsSliceInBounds"
}
+func minPhiLeq[T uint | int](x, y T) (z T) {
+ if x <= y {
+ z = x
+ } else {
+ z = y
+ }
+ return z
+}
+func maxPhiLeq[T uint | int](x, y T) (z T) {
+ if y <= x {
+ z = x
+ } else {
+ z = y
+ }
+ return z
+}
+func mathBasedOnPhiLosangeMinUFirstLeq(x uint, ensureAllBranchesCouldHappen func() bool) uint {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = minPhiLeq(x, maxc)
+ x = maxPhiLeq(x, minc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64U$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64U$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64U$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64U$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiLosangeMinUSecondLeq(x uint, ensureAllBranchesCouldHappen func() bool) uint {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = maxPhiLeq(x, minc)
+ x = minPhiLeq(x, maxc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64U$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64U$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64U$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64U$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiLosangeMinFirstLeq(x int, ensureAllBranchesCouldHappen func() bool) int {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = minPhiLeq(x, maxc)
+ x = maxPhiLeq(x, minc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiLosangeMinSecondLeq(x int, ensureAllBranchesCouldHappen func() bool) int {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = maxPhiLeq(x, minc)
+ x = minPhiLeq(x, maxc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64$"
+ return 42424242
+ }
+ return x
+}
+
+func minPhiLess[T uint | int](x, y T) (z T) {
+ if x < y {
+ z = x
+ } else {
+ z = y
+ }
+ return z
+}
+func maxPhiLess[T uint | int](x, y T) (z T) {
+ if y < x {
+ z = x
+ } else {
+ z = y
+ }
+ return z
+}
+func mathBasedOnPhiLosangeMinUFirstLess(x uint, ensureAllBranchesCouldHappen func() bool) uint {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = minPhiLess(x, maxc)
+ x = maxPhiLess(x, minc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64U$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64U$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64U$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64U$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiLosangeMinUSecondLess(x uint, ensureAllBranchesCouldHappen func() bool) uint {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = maxPhiLess(x, minc)
+ x = minPhiLess(x, maxc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64U$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64U$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64U$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64U$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiLosangeMinFirstLess(x int, ensureAllBranchesCouldHappen func() bool) int {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = minPhiLess(x, maxc)
+ x = maxPhiLess(x, minc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiLosangeMinSecondLess(x int, ensureAllBranchesCouldHappen func() bool) int {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = maxPhiLess(x, minc)
+ x = minPhiLess(x, maxc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64$"
+ return 42424242
+ }
+ return x
+}
+
+func mathBasedOnPhiBuiltinMinUFirst(x uint, ensureAllBranchesCouldHappen func() bool) uint {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = min(x, maxc)
+ x = max(x, minc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64U$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64U$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64U$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64U$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiBuiltinMinUSecond(x uint, ensureAllBranchesCouldHappen func() bool) uint {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = max(x, minc)
+ x = min(x, maxc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64U$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64U$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64U$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64U$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiBuiltinMinFirst(x int, ensureAllBranchesCouldHappen func() bool) int {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = min(x, maxc)
+ x = max(x, minc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64$"
+ return 42424242
+ }
+ return x
+}
+func mathBasedOnPhiBuiltinMinSecond(x int, ensureAllBranchesCouldHappen func() bool) int {
+ const maxc = 0xf2a
+ const minc = 0xf0a
+ x = max(x, minc)
+ x = min(x, maxc)
+
+ const k = 1
+ x += k
+
+ if ensureAllBranchesCouldHappen() && x > maxc+k { // ERROR "Disproved Less64$"
+ return 42
+ }
+ if ensureAllBranchesCouldHappen() && x <= maxc+k { // ERROR "Proved Leq64$"
+ return 4242
+ }
+ if ensureAllBranchesCouldHappen() && x < minc+k { // ERROR "Disproved Less64$"
+ return 424242
+ }
+ if ensureAllBranchesCouldHappen() && x >= minc+k { // ERROR "Proved Leq64$"
+ return 42424242
+ }
+ return x
+}
+
func issue16833(a, b []byte) {
n := copy(a, b)
_ = a[n:] // ERROR "Proved IsSliceInBounds"