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
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.
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
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
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 .
The text was updated successfully, but these errors were encountered: