]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add missing StringLen rule in prove
authorKeith Randall <khr@golang.org>
Sun, 22 Jun 2025 23:50:16 +0000 (16:50 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 24 Jul 2025 23:06:14 +0000 (16:06 -0700)
(StringLen (StringMake _ x)) == x, just like the rules we
currently have for slices.

This helps propagate string length knowledge to places which need it.

Change-Id: Ifdcf6d1f2d430c1c4bbac32e0ea74c188eae998e
Reviewed-on: https://go-review.googlesource.com/c/go/+/682777
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
src/cmd/compile/internal/ssa/prove.go
test/prove.go

index 0c0581690fe38fd832638b6c631184d0df3f8dcd..b8c952ef3350ad692cc730c8c11d008913995aee 100644 (file)
@@ -2267,6 +2267,10 @@ func addLocalFacts(ft *factsTable, b *Block) {
                        // the mod instruction executes (and thus panics if the
                        // modulus is 0). See issue 67625.
                        ft.update(b, v, v.Args[1], unsigned, lt)
+               case OpStringLen:
+                       if v.Args[0].Op == OpStringMake {
+                               ft.update(b, v, v.Args[0].Args[1], signed, eq)
+                       }
                case OpSliceLen:
                        if v.Args[0].Op == OpSliceMake {
                                ft.update(b, v, v.Args[0].Args[1], signed, eq)
index 8daa812e766994173f760eee1b50587168ee0fa2..5a4be3a5d54f874bf3506c0e3535e8ea699f3441 100644 (file)
@@ -2302,6 +2302,23 @@ func transitiveProofsThroughOverflowingUnsignedSub(x, y, z uint64) {
        }
 }
 
+func resliceString(s string) byte {
+       if len(s) >= 4 {
+               s = s[2:]   // ERROR "Proved IsSliceInBounds" "Proved slicemask not needed"
+               s = s[1:]   // ERROR "Proved IsSliceInBounds" "Proved slicemask not needed"
+               return s[0] // ERROR "Proved IsInBounds"
+       }
+       return 0
+}
+func resliceBytes(b []byte) byte {
+       if len(b) >= 4 {
+               b = b[2:]   // ERROR "Proved IsSliceInBounds" "Proved slicemask not needed"
+               b = b[1:]   // ERROR "Proved IsSliceInBounds" "Proved slicemask not needed"
+               return b[0] // ERROR "Proved IsInBounds"
+       }
+       return 0
+}
+
 //go:noinline
 func useInt(a int) {
 }