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 for interface conversions.
17 func mescapes(m M) { // ERROR "leaking param: m"
21 func mdoesnotescape(m M) { // ERROR "m does not escape"
24 // Tests for type stored directly in iface and with value receiver method.
40 i := 0 // ERROR "moved to heap: i"
53 i := 0 // ERROR "moved to heap: i"
55 // BAD: v does not escape to heap here
64 x.M() // ERROR "devirtualizing x.M"
67 i := 0 // ERROR "moved to heap: i"
80 // Tests for type stored indirectly in iface and with value receiver method.
93 var x M = v // ERROR "v does not escape"
97 i := 0 // ERROR "moved to heap: i"
99 var x M = v // ERROR "v escapes to heap"
105 var x M = v // ERROR "v does not escape"
110 i := 0 // ERROR "moved to heap: i"
112 var x M = v // ERROR "v does not escape"
114 sink = v1 // ERROR "v1 escapes to heap"
119 var x M = v // ERROR "v does not escape"
120 x.M() // ERROR "devirtualizing x.M"
123 i := 0 // ERROR "moved to heap: i"
125 var x M = v // ERROR "v escapes to heap"
131 var x M = v // ERROR "v does not escape"
136 // Tests for type stored directly in iface and with pointer receiver method.
144 func efaceEscape2() {
147 v := &M2{&i} // ERROR "&M2{...} does not escape"
152 i := 0 // ERROR "moved to heap: i"
153 v := &M2{&i} // ERROR "&M2{...} escapes to heap"
159 v := &M2{&i} // ERROR "&M2{...} does not escape"
165 i := 0 // ERROR "moved to heap: i"
166 v := &M2{&i} // ERROR "&M2{...} escapes to heap"
167 // BAD: v does not escape to heap here
173 i := 0 // ERROR "moved to heap: i"
174 v := &M2{&i} // ERROR "&M2{...} does not escape"
175 // BAD: v does not escape to heap here
181 i := 0 // ERROR "moved to heap: i"
182 v := &M2{&i} // ERROR "&M2{...} does not escape"
183 // BAD: v does not escape to heap here
191 v := &M2{&i} // ERROR "&M2{...} does not escape"
193 x.M() // ERROR "devirtualizing x.M"
196 i := 0 // ERROR "moved to heap: i"
197 v := &M2{&i} // ERROR "&M2{...} escapes to heap"
203 v := &M2{&i} // ERROR "&M2{...} does not escape"
217 func dotTypeEscape() *T2 { // #11931
219 x = &T1{p: new(int)} // ERROR "new\(int\) escapes to heap" "&T1{...} does not escape"
220 return &T2{ // ERROR "&T2{...} escapes to heap"
225 func dotTypeEscape2() { // #13805, #15796
231 var x interface{} = i // ERROR "i does not escape"
232 var y interface{} = j // ERROR "j does not escape"
235 *(&v), *(&ok) = y.(int)
241 var x interface{} = i // ERROR "i does not escape"
242 var y interface{} = j // ERROR "j does not escape"
244 sink = x.(int) // ERROR "x.\(int\) escapes to heap"
245 sink, *(&ok) = y.(int) // ERROR "autotmp_.* escapes to heap"
248 i := 0 // ERROR "moved to heap: i"
249 j := 0 // ERROR "moved to heap: j"
251 var x interface{} = &i
252 var y interface{} = &j
255 sink, *(&ok) = y.(*int)
260 type I interface{ M() }
263 var i I = T{} // ERROR "T\{\} does not escape"
264 i.M() // ERROR "partially devirtualizing i.M to T"