Skip to content

cmd/compile: escape analysis on slice allocations #39793

@hagaidayan

Description

@hagaidayan

What version of Go are you using (go version)?

$ go version 1.13

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

2.3 GHz Dual-Core Intel Core i5

Mac OSX

go env Output
$ go env

What did you do?

I wrote 2 similar programs that do the same thing
then built them with ' go build -gcflags "-m -m -l -N" '

A.
func main () {
x := 10
arr := make([]int, x)
arr[0] = 0
}

B.
func main () {
arr := make([]int, 10)
arr[0] = 0
}

What did you expect to see?

that both programs either do, or do not produce heap allocations

What did you see instead?

program A escapes to heap in line 3, while program B doesn't

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions