diff options
| author | Jorropo <jorropo.pgm@gmail.com> | 2025-08-12 12:49:13 +0200 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-08-13 07:21:20 -0700 |
| commit | 9fcb87c352b398aa650310160346c8d9bfcdcc45 (patch) | |
| tree | c426c5cfa86605b12960224d3c3f18a5be132829 /src/cmd | |
| parent | 9763ece873293c05560444cd6c6b8ea4cd2af1b4 (diff) | |
| download | go-9fcb87c352b398aa650310160346c8d9bfcdcc45.tar.xz | |
cmd/compile: teach prove about len's & cap's max based on the element size
Change-Id: I88056fada1ff488c199fce54cf737dbdd091214d
Reviewed-on: https://go-review.googlesource.com/c/go/+/695095
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/compile/internal/ssa/prove.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index b9b5d3386d..309229b4d7 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -1619,7 +1619,16 @@ func initLimit(v *Value) limit { lim = lim.unsignedMax(1) // length operations - case OpStringLen, OpSliceLen, OpSliceCap: + case OpSliceLen, OpSliceCap: + f := v.Block.Func + elemSize := uint64(v.Args[0].Type.Elem().Size()) + if elemSize > 0 { + heapSize := uint64(1)<<(uint64(f.Config.PtrSize)*8) - 1 + maximumElementsFittingInHeap := heapSize / elemSize + lim = lim.unsignedMax(maximumElementsFittingInHeap) + } + fallthrough + case OpStringLen: lim = lim.signedMin(0) } |
