]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix slice bounds check elimination after function inlining
authorYoulin Feng <fengyoulin@live.com>
Sat, 31 Jan 2026 03:23:41 +0000 (11:23 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 12 Feb 2026 17:29:09 +0000 (09:29 -0800)
commit2a1d605e7f5a0f8870abb9cc26edf27db3ad5452
treebbbb98ab6dd6925dadd60a8e21522560f309c362
parentf745645e58d8c2da47da402871d92eab4c498187
cmd/compile: fix slice bounds check elimination after function inlining

When creating a dynamically-sized slice, the compiler attempts to use a
stack-allocated buffer if the slice does not escape and its buffer size
is ≤ 32 bytes.

In this case, the SSA will contain a (OpPhi (OpSliceMake) (OpSliceMake))
value: one OpSliceMake uses the stack-allocated buffer, and the other
uses the heap-allocated buffer. The len and cap arguments for these two
OpSliceMake values are expected to be identical.

This CL enables the prove pass to recognize this scenario and handle
OpSliceLen and OpSliceCap as intended.

Fixes #77375

Change-Id: Id77a2473caf66d366f5c94108aa6cb6d3df5b887
Reviewed-on: https://go-review.googlesource.com/c/go/+/740840
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Junyang Shao <shaojunyang@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>
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/prove.go
src/cmd/compile/internal/ssa/rewritegeneric.go
test/codegen/issue77375.go [new file with mode: 0644]