-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: variables that only survive within the function escape to the heap #63964
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
By removing the mutex it still escapes Shorter example: https://go.dev/play/p/RFXBKkEFrfO go build -gcflags=-m=2 main.go
# command-line-arguments
./main.go:12:6: cannot inline escapes: function too complex: cost 87 exceeds budget 80
./main.go:13:12: can inline escapes.func1 with cost 4 as: func() { p.b = true }
./main.go:13:11: inlining call to sync.(*Once).Do
./main.go:13:11: inlining call to atomic.(*Uint32).Load
./main.go:18:6: can inline doesntescape with cost 4 as: func(*V) { p.b = true }
./main.go:22:6: can inline main with cost 73 as: func() { vv = <nil>; escapes(&vv); doesntescape(&vv) }
./main.go:25:14: inlining call to doesntescape
./main.go:12:14: escapes capturing by value: p (addr=false assign=false width=8)
./main.go:12:14: parameter p leaks to {heap} with derefs=0:
./main.go:12:14: flow: sync.o = p:
./main.go:12:14: from p.once (dot of pointer) at ./main.go:13:3
./main.go:12:14: from p.once (address-of) at ./main.go:13:8
./main.go:12:14: from sync.o, sync.f := p.once, func literal (assign-pair) at ./main.go:13:11
./main.go:12:14: flow: {heap} = sync.o:
./main.go:12:14: from (*sync.Once).doSlow(sync.o, sync.f) (call parameter) at ./main.go:13:11
./main.go:12:14: leaking param: p
./main.go:13:12: func literal does not escape
./main.go:18:19: p does not escape
./main.go:23:6: vv escapes to heap:
./main.go:23:6: flow: {heap} = &vv:
./main.go:23:6: from &vv (address-of) at ./main.go:24:10
./main.go:23:6: from escapes(&vv) (call parameter) at ./main.go:24:9
./main.go:23:6: moved to heap: vv |
cc @golang/compiler |
Thanks for finding that! I agree, it looks like the same issue. Closing this one as a duplicate. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes.
What operating system and processor architecture are you using (
go env
)?Can be reproduced in https://go.dev/play
What did you do?
This is the minimum copy code I have written.
https://go.dev/play/p/CMcVGAsizeN?v=gotip
What did you expect to see?
I want to see variables that only survive in function memory being allocated to the stack.
What did you see instead?
I see variables that only survive in function memory being allocated to the heap.
The text was updated successfully, but these errors were encountered: