go/test/fixedbugs/issue41635.go
Mateusz Poliwczak ba3f568988 cmd/compile: determine static values of len and cap in make() calls
This change improves escape analysis by attempting to
deduce static values for the len and cap parameters,
allowing allocations to be made on the stack.

Change-Id: I1161019aed9f60cf2c2fe4d405da94ad415231ac
GitHub-Last-Rev: d78c1b4ca55fa53282e665009f689d0b013f1434
GitHub-Pull-Request: golang/go#71693
Reviewed-on: https://go-review.googlesource.com/c/go/+/649035
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2025-02-19 13:38:58 -08:00

18 lines
536 B
Go

//errorcheck -0 -m -m
// Copyright 2020 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 p
func f() { // ERROR ""
n, m := 100, 200
_ = make([]byte, 1<<17) // ERROR "too large for stack" ""
_ = make([]byte, 100, 1<<17) // ERROR "too large for stack" ""
_ = make([]byte, n, 1<<17) // ERROR "too large for stack" ""
_ = make([]byte, n) // ERROR "does not escape"
_ = make([]byte, 100, m) // ERROR "does not escape"
}