Skip to content

cmd/compile: incorrect escape reason for heap-allocated array with var len/cap #24578

@ALTree

Description

@ALTree
$ go version
go version devel +377a2cb2d2 Tue Mar 27 18:03:39 2018 +0000 linux/amd64

When compiling

package p

func f() {
	n := 32
	workBuf := make([]int, 0, n)
	// ... do some local work on workBuf
	_ = workBuf
}

-m -m says:

./test.go:5:17: make([]int, 0, n) escapes to heap
	from make([]int, 0, n) (too large for stack) at ./test.go:5:17

The given reason for the escape ("too large for stack") is wrong. The same-sized allocation is put on the stack when the bound is a const 32:

./test.go:5:17: f make([]int, 0, 32) does not escape

The real reason for the escape is that we don't stack-allocate arrays when the len/cap is a variable.

Someone using -m -m when investigating an allocation profile may be thrown off by the incorrect explanation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions