Skip to content

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

Closed

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.

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Mar 28, 2018
  2. added this to the Unplanned milestone on Mar 28, 2018
  3. gopherbot commented on Mar 28, 2018

    @gopherbot
    Contributor

    Change https://golang.org/cl/102895 mentions this issue: cmd/compile: more accurate escape reason for nonconst array

  4. locked and limited conversation to collaborators on Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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