diff options
| author | Jorropo <jorropo.pgm@gmail.com> | 2025-07-04 09:21:03 +0200 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-07-24 13:48:55 -0700 |
| commit | e5f202bb60b246a7aee2a14b95ca399fd243accd (patch) | |
| tree | 9a6f3181744e236d5c81cb8a8324e3a494aaf9cc /test | |
| parent | bd80f74bc154585237a3c1b636e30dab6d781923 (diff) | |
| download | go-e5f202bb60b246a7aee2a14b95ca399fd243accd.tar.xz | |
cmd/compile: learn transitive proofs for safe unsigned adds
I've split this into it's own CL to make git bisect more effective.
Change-Id: Iaab5f0bd2ad51e86ced8c6b8fbd371eb75eeef14
Reviewed-on: https://go-review.googlesource.com/c/go/+/685815
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Mark Freeman <mark@golang.org>
Diffstat (limited to 'test')
| -rw-r--r-- | test/prove.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/prove.go b/test/prove.go index faf0b79237..e843edcbf0 100644 --- a/test/prove.go +++ b/test/prove.go @@ -2041,6 +2041,69 @@ func cvtBoolToUint8BCE(b bool, a [2]int64) int64 { return a[c] // ERROR "Proved IsInBounds$" } +func transitiveProofsThroughNonOverflowingUnsignedAdd(x, y, z uint64) { + x &= 1<<63 - 1 + y &= 1<<63 - 1 + + a := x + y + if a > z { + return + } + + if x > z { // ERROR "Disproved Less64U$" + return + } + if y > z { // ERROR "Disproved Less64U$" + return + } + if a == x { + return + } + if a == y { + return + } + + x |= 1 + y |= 1 + a = x + y + if a == x { // ERROR "Disproved Eq64$" + return + } + if a == y { // ERROR "Disproved Eq64$" + return + } +} + +func transitiveProofsThroughOverflowingUnsignedAdd(x, y, z uint64) { + a := x + y + if a > z { + return + } + + if x > z { + return + } + if y > z { + return + } + if a == x { + return + } + if a == y { + return + } + + x |= 1 + y |= 1 + a = x + y + if a == x { + return + } + if a == y { + return + } +} + //go:noinline func useInt(a int) { } |
