aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMateusz Poliwczak <mpoliwczak34@gmail.com>2025-09-26 20:47:45 +0200
committerGopher Robot <gobot@golang.org>2025-10-02 11:02:07 -0700
commit84db201ae18c889acdefe20c8a903b188328f16d (patch)
treee77673d97ea38e5225def5cc4e2558e62e3b76e9 /test
parent5799c139a77e9c3a5750c90ebda538131f4517d6 (diff)
downloadgo-84db201ae18c889acdefe20c8a903b188328f16d.tar.xz
cmd/compile: propagate len([]T{}) to make builtin to allow stack allocation
Updates #75620 Change-Id: I6a6a6964af4512e30eb4806e1dc7b0fd0835744f Reviewed-on: https://go-review.googlesource.com/c/go/+/707255 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/escape_make_non_const.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/escape_make_non_const.go b/test/escape_make_non_const.go
index 7a9b28d5e3..11854ac4f4 100644
--- a/test/escape_make_non_const.go
+++ b/test/escape_make_non_const.go
@@ -106,3 +106,18 @@ type m struct {
func newM(l int) m { // ERROR "can inline"
return m{make(map[string]int, l)} // ERROR "make.*escapes to heap"
}
+
+//go:noinline
+func testLenOfSliceLit() {
+ ints := []int{0, 1, 2, 3, 4, 5} // ERROR "\[\]int\{\.\.\.\} does not escape"'
+ _ = make([]int, len(ints)) // ERROR "make\(\[\]int, 6\) does not escape"
+ _ = allocLenOf(ints) // ERROR "inlining call", "make\(\[\]int, 6\) does not escape"
+
+ _ = make([]int, 2, len(ints)) // ERROR "make\(\[\]int, 2, 6\) does not escape"
+ _ = make([]int, len(ints), 2) // ERROR "make\(\[\]int, len\(ints\), 2\) does not escape"
+ _ = make([]int, 10, len(ints)) // ERROR "make\(\[\]int, 10, 6\) does not escape"
+}
+
+func allocLenOf(s []int) []int { // ERROR "can inline" "s does not escape"
+ return make([]int, len(s)) // ERROR "escapes to heap"
+}