From 2a1d605e7f5a0f8870abb9cc26edf27db3ad5452 Mon Sep 17 00:00:00 2001 From: Youlin Feng Date: Sat, 31 Jan 2026 11:23:41 +0800 Subject: cmd/compile: fix slice bounds check elimination after function inlining MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Junyang Shao LUCI-TryBot-Result: Go LUCI Auto-Submit: Keith Randall Reviewed-by: Keith Randall --- test/codegen/issue77375.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/codegen/issue77375.go (limited to 'test/codegen') diff --git a/test/codegen/issue77375.go b/test/codegen/issue77375.go new file mode 100644 index 0000000000..f74ce399fa --- /dev/null +++ b/test/codegen/issue77375.go @@ -0,0 +1,39 @@ +// asmcheck + +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package codegen + +func Range(n int) []int { + m := make([]int, n) + + for i := 0; i < n; i++ { + m[i] = i + } + + for i := range n { + m[i] = i + } + + for i := range len(m) { + m[i] = i + } + + for i := range m { + m[i] = i + } + + return m +} + +func F(size int) { + // amd64:-`.*panicBounds` + // arm64:-`.*panicBounds` + Range(size) +} + +func main() { + F(-1) +} -- cgit v1.3-6-g1900