You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version devel +4909ecc Sun Mar 26 21:29:31 2017 +0000 linux/amd64
What operating system and processor architecture are you using (go env)?
linux/amd64
What did you do?
package main
type Buf struct {
buf [100]byte
off int
}
// Insert inserts b at offset i.
func (a *Buf) Insert(i int, b byte) {
a.off++
copy(a.buf[i+1:a.off], a.buf[i:a.off-1])
a.buf[i] = b
}
func main() {
var a Buf
a.Insert(0, 1)
}
What did you expect to see?
a does not escape to the heap
What did you see instead?
./escape.go:9:31: leaking param content: a
./escape.go:9:31: from a.buf (dot of pointer) at ./escape.go:11:26
./escape.go:9:31: from a.buf (address-of) at ./escape.go:11:30
./escape.go:9:31: from a.buf[i:a.off - 1] (slice) at ./escape.go:11:30
./escape.go:9:31: from *a.buf[i:a.off - 1] (indirection) at ./escape.go:11:30
./escape.go:9:31: from copy(a.buf[i + 1:a.off], a.buf[i:a.off - 1]) (copied slice) at ./escape.go:11:6
The text was updated successfully, but these errors were encountered:
I think you're misinterpreting the escape analysis output. a is not escaping, its content is. Its contents contains no pointers, so that isn't really relevant to a itself escaping.
The assembly output is clear that a is allocated on the stack in main.
Reopen if I'm missing something. Certainly the escape analysis output could be clarified.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version devel +4909ecc Sun Mar 26 21:29:31 2017 +0000 linux/amd64
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
What did you expect to see?
a
does not escape to the heapWhat did you see instead?
The text was updated successfully, but these errors were encountered: