Skip to content
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: convT2E calls should allocate on the stack when they can #13807

Closed
randall77 opened this issue Jan 3, 2016 · 1 comment
Closed

Comments

@randall77
Copy link
Contributor

package main

type T struct {
    x int
}

func (t *T) Set1(i interface{}) {
    t.x = i.(int)
}
func (t *T) Set2(i interface{}) {
    x := i.(int)
    t.x = x
}

func main() {
    var t T
    t.Set1(5)
    t.Set2(7)
}

Both Set1 and Set2 are inlined. At the Set1 callsite, the call to convT2E to build the interface{} is passed nil for a storage location for the int. At the Set2 callsite, it is passed a pointer to a stack location. We should always use the stack allocation in these cases, like the Set2 callsite does. The Set1 callsite ends up mallocing.

Probably some interaction between inlining and the optimization to pass a non-nil storage location to convT2E.

See issue #13805 .

@randall77 randall77 added this to the Go1.7 milestone Jan 3, 2016
@randall77 randall77 changed the title calls convT2E should allocate on the stack when it can convT2E calls should allocate on the stack when they can Jan 3, 2016
@ianlancetaylor ianlancetaylor changed the title convT2E calls should allocate on the stack when they can cmd/compile: convT2E calls should allocate on the stack when they can Jan 4, 2016
@randall77 randall77 modified the milestones: Go1.8, Go1.7 Apr 29, 2016
@randall77
Copy link
Contributor Author

This is now fixed at tip.

@golang golang locked and limited conversation to collaborators Oct 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants