3 // Copyright 2015 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test escape analysis with respect to field assignments.
24 i := 0 // ERROR "moved to heap: i$"
31 i := 0 // ERROR "moved to heap: i$"
33 // BAD: &i should not escape
39 i := 0 // ERROR "moved to heap: i$"
42 sink = x // ERROR "x escapes to heap"
46 i := 0 // ERROR "moved to heap: i$"
50 sink = x // ERROR "x escapes to heap"
54 i := 0 // ERROR "moved to heap: i$"
56 // BAD: &i should not escape here
61 // BAD: we are not leaking param x, only x.p2
62 func field6(x *X) { // ERROR "leaking param content: x$"
67 i := 0 // ERROR "moved to heap: i$"
69 // BAD: &i should not escape
85 i := 0 // ERROR "moved to heap: i$"
95 i := 0 // ERROR "moved to heap: i$"
101 sink = y1.x // ERROR "y1\.x escapes to heap"
105 i := 0 // ERROR "moved to heap: i$"
107 // BAD: &i should not escape
116 i := 0 // ERROR "moved to heap: i$"
122 i := 0 // ERROR "moved to heap: i$"
123 // BAD: &i should not escape
129 i := 0 // ERROR "moved to heap: i$"
130 x := &X{p1: &i} // ERROR "&X{...} does not escape$"
135 i := 0 // ERROR "moved to heap: i$"
136 // BAD: &i should not escape
137 x := &X{p1: &i} // ERROR "&X{...} does not escape$"
142 i := 0 // ERROR "moved to heap: i$"
143 x := &X{p1: &i} // ERROR "&X{...} escapes to heap$"
148 i := 0 // ERROR "moved to heap: i$"
150 // BAD: &i should not escape
152 var iface interface{} = x // ERROR "x does not escape"
158 i := 0 // ERROR "moved to heap: i$"
161 var iface interface{} = x // ERROR "x does not escape"
167 i := 0 // ERROR "moved to heap: i$"
169 // BAD: &i should not escape
171 var iface interface{} = x // ERROR "x does not escape"
172 y, _ := iface.(Y) // Put X, but extracted Y. The cast will fail, so y is zero initialized.
173 sink = y // ERROR "y escapes to heap"