Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(352)

Delta Between Two Patch Sets: test/escape2.go

Issue 5333049: code review 5333049: gc: test + fix escape analysis bug (Closed)
Left Patch Set: Created 12 years, 5 months ago
Right Patch Set: diff -r 64a7c82147a0 https://go.googlecode.com/hg/ Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/gc/esc.c ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // errchk -0 $G -m $D/$F.go 1 // errchk -0 $G -m $D/$F.go
2 2
3 // Copyright 2010 The Go Authors. All rights reserved. 3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style 4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file. 5 // license that can be found in the LICENSE file.
6 6
7 package foo 7 package foo
8 8
9 import "unsafe" 9 import (
10 » "fmt"
11 » "unsafe"
12 )
10 13
11 var gxx *int 14 var gxx *int
12 15
13 func foo1(x int) { // ERROR "moved to heap: x" 16 func foo1(x int) { // ERROR "moved to heap: x"
14 » gxx = &x // ERROR "&x escapes to heap" 17 » gxx = &x // ERROR "&x escapes to heap"
15 } 18 }
16 19
17 func foo2(yy *int) { // ERROR "leaking param: yy" 20 func foo2(yy *int) { // ERROR "leaking param: yy"
18 gxx = yy 21 gxx = yy
19 } 22 }
20 23
21 func foo3(x int) *int { // ERROR "moved to heap: x" 24 func foo3(x int) *int { // ERROR "moved to heap: x"
22 » return &x // ERROR "&x escapes to heap" 25 » return &x // ERROR "&x escapes to heap"
23 } 26 }
24 27
25 type T *T 28 type T *T
26 29
27 func foo3b(t T) { // ERROR "leaking param: t" 30 func foo3b(t T) { // ERROR "leaking param: t"
28 *t = t 31 *t = t
29 } 32 }
30 33
31 // xx isn't going anywhere, so use of yy is ok 34 // xx isn't going anywhere, so use of yy is ok
32 func foo4(xx, yy *int) { // ERROR "xx does not escape" "yy does not escape" 35 func foo4(xx, yy *int) { // ERROR "xx does not escape" "yy does not escape"
33 xx = yy 36 xx = yy
34 } 37 }
35 38
36 // xx isn't going anywhere, so taking address of yy is ok 39 // xx isn't going anywhere, so taking address of yy is ok
37 func foo5(xx **int, yy *int) { // ERROR "xx does not escape" "yy does not escape " 40 func foo5(xx **int, yy *int) { // ERROR "xx does not escape" "yy does not escape "
38 » xx = &yy // ERROR "&yy does not escape" 41 » xx = &yy // ERROR "&yy does not escape"
39 } 42 }
40 43
41 func foo6(xx **int, yy *int) { // ERROR "xx does not escape" "leaking param: yy" 44 func foo6(xx **int, yy *int) { // ERROR "xx does not escape" "leaking param: yy"
42 *xx = yy 45 *xx = yy
43 } 46 }
44 47
45 func foo7(xx **int, yy *int) { // ERROR "xx does not escape" "yy does not escape " 48 func foo7(xx **int, yy *int) { // ERROR "xx does not escape" "yy does not escape "
46 **xx = *yy 49 **xx = *yy
47 } 50 }
48 51
49 func foo8(xx, yy *int) int { // ERROR "xx does not escape" "yy does not escape" 52 func foo8(xx, yy *int) int { // ERROR "xx does not escape" "yy does not escape"
50 xx = yy 53 xx = yy
51 return *xx 54 return *xx
52 } 55 }
53 56
54 func foo9(xx, yy *int) *int { // ERROR "leaking param: xx" "leaking param: yy" 57 func foo9(xx, yy *int) *int { // ERROR "leaking param: xx" "leaking param: yy"
55 xx = yy 58 xx = yy
56 return xx 59 return xx
57 } 60 }
58 61
59 func foo10(xx, yy *int) { // ERROR "xx does not escape" "yy does not escape" 62 func foo10(xx, yy *int) { // ERROR "xx does not escape" "yy does not escape"
60 *xx = *yy 63 *xx = *yy
61 } 64 }
62 65
63 func foo11() int { 66 func foo11() int {
64 x, y := 0, 42 67 x, y := 0, 42
65 » xx := &x // ERROR "&x does not escape" 68 » xx := &x // ERROR "&x does not escape"
66 » yy := &y // ERROR "&y does not escape" 69 » yy := &y // ERROR "&y does not escape"
67 *xx = *yy 70 *xx = *yy
68 return x 71 return x
69 } 72 }
70 73
71 var xxx **int 74 var xxx **int
72 75
73 func foo12(yyy **int) { // ERROR "leaking param: yyy" 76 func foo12(yyy **int) { // ERROR "leaking param: yyy"
74 xxx = yyy 77 xxx = yyy
75 } 78 }
76 79
77 func foo13(yyy **int) { // ERROR "yyy does not escape" 80 func foo13(yyy **int) { // ERROR "yyy does not escape"
78 *xxx = *yyy 81 *xxx = *yyy
79 } 82 }
80 83
81 func foo14(yyy **int) { // ERROR "yyy does not escape" 84 func foo14(yyy **int) { // ERROR "yyy does not escape"
82 **xxx = **yyy 85 **xxx = **yyy
83 } 86 }
84 87
85 func foo15(yy *int) { // ERROR "moved to heap: yy" 88 func foo15(yy *int) { // ERROR "moved to heap: yy"
86 » xxx = &yy // ERROR "&yy escapes to heap" 89 » xxx = &yy // ERROR "&yy escapes to heap"
87 } 90 }
88 91
89 func foo16(yy *int) { // ERROR "leaking param: yy" 92 func foo16(yy *int) { // ERROR "leaking param: yy"
90 *xxx = yy 93 *xxx = yy
91 } 94 }
92 95
93 func foo17(yy *int) { // ERROR "yy does not escape" 96 func foo17(yy *int) { // ERROR "yy does not escape"
94 **xxx = *yy 97 **xxx = *yy
95 } 98 }
96 99
97 func foo18(y int) { // ERROR "moved to heap: "y" 100 func foo18(y int) { // ERROR "moved to heap: "y"
98 » *xxx = &y // ERROR "&y escapes to heap" 101 » *xxx = &y // ERROR "&y escapes to heap"
99 } 102 }
100 103
101 func foo19(y int) { 104 func foo19(y int) {
102 **xxx = y 105 **xxx = y
103 } 106 }
104 107
105 type Bar struct { 108 type Bar struct {
106 i int 109 i int
107 ii *int 110 ii *int
108 } 111 }
(...skipping 11 matching lines...) Expand all
120 } 123 }
121 124
122 func (b *Bar) NoLeak() int { // ERROR "b does not escape" 125 func (b *Bar) NoLeak() int { // ERROR "b does not escape"
123 return *(b.ii) 126 return *(b.ii)
124 } 127 }
125 128
126 func (b *Bar) AlsoNoLeak() *int { // ERROR "b does not escape" 129 func (b *Bar) AlsoNoLeak() *int { // ERROR "b does not escape"
127 return b.ii 130 return b.ii
128 } 131 }
129 132
130 func goLeak(b *Bar) { // ERROR "leaking param: b" 133 func goLeak(b *Bar) { // ERROR "leaking param: b"
131 go b.NoLeak() 134 go b.NoLeak()
132 } 135 }
133 136
134 type Bar2 struct { 137 type Bar2 struct {
135 i [12]int 138 i [12]int
136 ii []int 139 ii []int
137 } 140 }
138 141
139 func NewBar2() *Bar2 { 142 func NewBar2() *Bar2 {
140 return &Bar2{[12]int{42}, nil} // ERROR "&Bar2 literal escapes to heap" 143 return &Bar2{[12]int{42}, nil} // ERROR "&Bar2 literal escapes to heap"
141 } 144 }
142 145
143 func (b *Bar2) NoLeak() int { // ERROR "b does not escape" 146 func (b *Bar2) NoLeak() int { // ERROR "b does not escape"
144 return b.i[0] 147 return b.i[0]
145 } 148 }
146 149
147 func (b *Bar2) Leak() []int { // ERROR "leaking param: b" 150 func (b *Bar2) Leak() []int { // ERROR "leaking param: b"
148 » return b.i[:] // ERROR "&b.i escapes to heap" 151 » return b.i[:] // ERROR "&b.i escapes to heap"
149 } 152 }
150 153
151 func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape" 154 func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape"
152 return b.ii[0:1] 155 return b.ii[0:1]
153 } 156 }
154 157
155 func (b *Bar2) LeakSelf() { // ERROR "leaking param: b" 158 func (b *Bar2) LeakSelf() { // ERROR "leaking param: b"
156 » b.ii = b.i[0:4] // ERROR "&b.i escapes to heap" 159 » b.ii = b.i[0:4] // ERROR "&b.i escapes to heap"
157 } 160 }
158 161
159 func (b *Bar2) LeakSelf2() { // ERROR "leaking param: b" 162 func (b *Bar2) LeakSelf2() { // ERROR "leaking param: b"
160 var buf []int 163 var buf []int
161 » buf = b.i[0:] // ERROR "&b.i escapes to heap" 164 » buf = b.i[0:] // ERROR "&b.i escapes to heap"
162 b.ii = buf 165 b.ii = buf
163 } 166 }
164 167
165 func foo21() func() int { 168 func foo21() func() int {
166 » x := 42 // ERROR "moved to heap: x" 169 » x := 42 // ERROR "moved to heap: x"
167 » return func() int { // ERROR "func literal escapes to heap" 170 » return func() int { // ERROR "func literal escapes to heap"
168 » » return x // ERROR "&x escapes to heap" 171 » » return x // ERROR "&x escapes to heap"
169 } 172 }
170 } 173 }
171 174
172 func foo22() int { 175 func foo22() int {
173 x := 42 176 x := 42
174 » return func() int { // ERROR "func literal does not escape" 177 » return func() int { // ERROR "func literal does not escape"
175 return x 178 return x
176 }() 179 }()
177 } 180 }
178 181
179 func foo23(x int) func() int { // ERROR "moved to heap: x" 182 func foo23(x int) func() int { // ERROR "moved to heap: x"
180 » return func() int { // ERROR "func literal escapes to heap" 183 » return func() int { // ERROR "func literal escapes to heap"
181 » » return x // ERROR "&x escapes to heap" 184 » » return x // ERROR "&x escapes to heap"
182 } 185 }
183 } 186 }
184 187
185 func foo23a(x int) func() int { // ERROR "moved to heap: x" 188 func foo23a(x int) func() int { // ERROR "moved to heap: x"
186 » f := func() int { // ERROR "func literal escapes to heap" 189 » f := func() int { // ERROR "func literal escapes to heap"
187 » » return x // ERROR "&x escapes to heap" 190 » » return x // ERROR "&x escapes to heap"
188 } 191 }
189 return f 192 return f
190 } 193 }
191 194
192 func foo23b(x int) *(func() int) { // ERROR "moved to heap: x" 195 func foo23b(x int) *(func() int) { // ERROR "moved to heap: x"
193 f := func() int { return x } // ERROR "moved to heap: f" "func literal e scapes to heap" "&x escapes to heap" 196 f := func() int { return x } // ERROR "moved to heap: f" "func literal e scapes to heap" "&x escapes to heap"
194 » return &f // ERROR "&f escapes to heap" 197 » return &f // ERROR "&f escapes to heap"
195 } 198 }
196 199
197 func foo24(x int) int { 200 func foo24(x int) int {
198 » return func() int { // ERROR "func literal does not escape" 201 » return func() int { // ERROR "func literal does not escape"
199 return x 202 return x
200 }() 203 }()
201 } 204 }
202 205
203 var x *int 206 var x *int
204 207
205 func fooleak(xx *int) int { // ERROR "leaking param: xx" 208 func fooleak(xx *int) int { // ERROR "leaking param: xx"
206 x = xx 209 x = xx
207 return *x 210 return *x
208 } 211 }
209 212
210 func foonoleak(xx *int) int { // ERROR "xx does not escape" 213 func foonoleak(xx *int) int { // ERROR "xx does not escape"
211 return *x + *xx 214 return *x + *xx
212 } 215 }
213 216
214 func foo31(x int) int { // ERROR "moved to heap: x" 217 func foo31(x int) int { // ERROR "moved to heap: x"
215 » return fooleak(&x) // ERROR "&x escapes to heap" 218 » return fooleak(&x) // ERROR "&x escapes to heap"
216 } 219 }
217 220
218 func foo32(x int) int { 221 func foo32(x int) int {
219 » return foonoleak(&x) // ERROR "&x does not escape" 222 » return foonoleak(&x) // ERROR "&x does not escape"
220 } 223 }
221 224
222 type Foo struct { 225 type Foo struct {
223 xx *int 226 xx *int
224 x int 227 x int
225 } 228 }
226 229
227 var F Foo 230 var F Foo
228 var pf *Foo 231 var pf *Foo
229 232
230 func (f *Foo) fooleak() { // ERROR "leaking param: f" 233 func (f *Foo) fooleak() { // ERROR "leaking param: f"
231 pf = f 234 pf = f
232 } 235 }
233 236
234 func (f *Foo) foonoleak() { // ERROR "f does not escape" 237 func (f *Foo) foonoleak() { // ERROR "f does not escape"
235 F.x = f.x 238 F.x = f.x
236 } 239 }
237 240
238 func (f *Foo) Leak() { // ERROR "leaking param: f" 241 func (f *Foo) Leak() { // ERROR "leaking param: f"
239 f.fooleak() 242 f.fooleak()
240 } 243 }
241 244
242 func (f *Foo) NoLeak() { // ERROR "f does not escape" 245 func (f *Foo) NoLeak() { // ERROR "f does not escape"
243 f.foonoleak() 246 f.foonoleak()
244 } 247 }
245 248
246 func foo41(x int) { // ERROR "moved to heap: x" 249 func foo41(x int) { // ERROR "moved to heap: x"
247 » F.xx = &x // ERROR "&x escapes to heap" 250 » F.xx = &x // ERROR "&x escapes to heap"
248 } 251 }
249 252
250 func (f *Foo) foo42(x int) { // ERROR "f does not escape" "moved to heap: x" 253 func (f *Foo) foo42(x int) { // ERROR "f does not escape" "moved to heap: x"
251 » f.xx = &x // ERROR "&x escapes to heap" 254 » f.xx = &x // ERROR "&x escapes to heap"
252 } 255 }
253 256
254 func foo43(f *Foo, x int) { // ERROR "f does not escape" "moved to heap: x" 257 func foo43(f *Foo, x int) { // ERROR "f does not escape" "moved to heap: x"
255 » f.xx = &x // ERROR "&x escapes to heap" 258 » f.xx = &x // ERROR "&x escapes to heap"
256 } 259 }
257 260
258 func foo44(yy *int) { // ERROR "leaking param: yy" 261 func foo44(yy *int) { // ERROR "leaking param: yy"
259 F.xx = yy 262 F.xx = yy
260 } 263 }
261 264
262 func (f *Foo) foo45() { // ERROR "f does not escape" 265 func (f *Foo) foo45() { // ERROR "f does not escape"
263 F.x = f.x 266 F.x = f.x
264 } 267 }
265 268
266 func (f *Foo) foo46() { // ERROR "f does not escape" 269 func (f *Foo) foo46() { // ERROR "f does not escape"
267 F.xx = f.xx 270 F.xx = f.xx
268 } 271 }
269 272
270 func (f *Foo) foo47() { // ERROR "leaking param: f" 273 func (f *Foo) foo47() { // ERROR "leaking param: f"
271 » f.xx = &f.x // ERROR "&f.x escapes to heap" 274 » f.xx = &f.x // ERROR "&f.x escapes to heap"
272 } 275 }
273 276
274 var ptrSlice []*int 277 var ptrSlice []*int
275 278
276 func foo50(i *int) { // ERROR "leaking param: i" 279 func foo50(i *int) { // ERROR "leaking param: i"
277 ptrSlice[0] = i 280 ptrSlice[0] = i
278 } 281 }
279 282
280 var ptrMap map[*int]*int 283 var ptrMap map[*int]*int
281 284
282 func foo51(i *int) { // ERROR "leaking param: i" 285 func foo51(i *int) { // ERROR "leaking param: i"
283 ptrMap[i] = i 286 ptrMap[i] = i
284 } 287 }
285 288
286 func indaddr1(x int) *int { // ERROR "moved to heap: x" 289 func indaddr1(x int) *int { // ERROR "moved to heap: x"
287 » return &x // ERROR "&x escapes to heap" 290 » return &x // ERROR "&x escapes to heap"
288 } 291 }
289 292
290 func indaddr2(x *int) *int { // ERROR "leaking param: x" 293 func indaddr2(x *int) *int { // ERROR "leaking param: x"
291 » return *&x // ERROR "&x does not escape" 294 » return *&x // ERROR "&x does not escape"
292 } 295 }
293 296
294 func indaddr3(x *int32) *int { // ERROR "leaking param: x" 297 func indaddr3(x *int32) *int { // ERROR "leaking param: x"
295 » return *(**int)(unsafe.Pointer(&x)) // ERROR "&x does not escape" 298 » return *(**int)(unsafe.Pointer(&x)) // ERROR "&x does not escape"
296 } 299 }
297 300
298 // From package math: 301 // From package math:
299 302
300 func Float32bits(f float32) uint32 { 303 func Float32bits(f float32) uint32 {
301 » return *(*uint32)(unsafe.Pointer(&f)) // ERROR "&f does not escape" 304 » return *(*uint32)(unsafe.Pointer(&f)) // ERROR "&f does not escape"
302 } 305 }
303 306
304 func Float32frombits(b uint32) float32 { 307 func Float32frombits(b uint32) float32 {
305 » return *(*float32)(unsafe.Pointer(&b)) // ERROR "&b does not escape" 308 » return *(*float32)(unsafe.Pointer(&b)) // ERROR "&b does not escape"
306 } 309 }
307 310
308 func Float64bits(f float64) uint64 { 311 func Float64bits(f float64) uint64 {
309 » return *(*uint64)(unsafe.Pointer(&f)) // ERROR "&f does not escape" 312 » return *(*uint64)(unsafe.Pointer(&f)) // ERROR "&f does not escape"
310 } 313 }
311 314
312 func Float64frombits(b uint64) float64 { 315 func Float64frombits(b uint64) float64 {
313 » return *(*float64)(unsafe.Pointer(&b)) // ERROR "&b does not escape" 316 » return *(*float64)(unsafe.Pointer(&b)) // ERROR "&b does not escape"
314 } 317 }
315 318
316 // contrast with 319 // contrast with
317 func float64bitsptr(f float64) *uint64 { // ERROR "moved to heap: f" 320 func float64bitsptr(f float64) *uint64 { // ERROR "moved to heap: f"
318 » return (*uint64)(unsafe.Pointer(&f)) // ERROR "&f escapes to heap" 321 » return (*uint64)(unsafe.Pointer(&f)) // ERROR "&f escapes to heap"
319 } 322 }
320 323
321 func float64ptrbitsptr(f *float64) *uint64 { // ERROR "leaking param: f" 324 func float64ptrbitsptr(f *float64) *uint64 { // ERROR "leaking param: f"
322 return (*uint64)(unsafe.Pointer(f)) 325 return (*uint64)(unsafe.Pointer(f))
323 } 326 }
324 327
325 func typesw(i interface{}) *int { // ERROR "leaking param: i" 328 func typesw(i interface{}) *int { // ERROR "leaking param: i"
326 switch val := i.(type) { 329 switch val := i.(type) {
327 case *int: 330 case *int:
328 return val 331 return val
329 case *int8: 332 case *int8:
330 v := int(*val) // ERROR "moved to heap: v" 333 v := int(*val) // ERROR "moved to heap: v"
331 » » return &v // ERROR "&v escapes to heap" 334 » » return &v // ERROR "&v escapes to heap"
332 } 335 }
333 return nil 336 return nil
334 } 337 }
335 338
336 func exprsw(i *int) *int { // ERROR "leaking param: i" 339 func exprsw(i *int) *int { // ERROR "leaking param: i"
337 switch j := i; *j + 110 { 340 switch j := i; *j + 110 {
338 case 12: 341 case 12:
339 return j 342 return j
340 case 42: 343 case 42:
341 return nil 344 return nil
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 func foo64b(m M) { // ERROR "leaking param: m" 405 func foo64b(m M) { // ERROR "leaking param: m"
403 defer m.M() 406 defer m.M()
404 } 407 }
405 408
406 type MV int 409 type MV int
407 410
408 func (MV) M() {} 411 func (MV) M() {}
409 412
410 func foo65() { 413 func foo65() {
411 var mv MV 414 var mv MV
412 » foo63(&mv) // ERROR "&mv does not escape" 415 » foo63(&mv) // ERROR "&mv does not escape"
413 } 416 }
414 417
415 func foo66() { 418 func foo66() {
416 » var mv MV // ERROR "moved to heap: mv" 419 » var mv MV // ERROR "moved to heap: mv"
417 » foo64(&mv) // ERROR "&mv escapes to heap" 420 » foo64(&mv) // ERROR "&mv escapes to heap"
418 } 421 }
419 422
420 func foo67() { 423 func foo67() {
421 var mv MV 424 var mv MV
422 foo63(mv) 425 foo63(mv)
423 } 426 }
424 427
425 func foo68() { 428 func foo68() {
426 var mv MV 429 var mv MV
427 foo64(mv) // escapes but it's an int so irrelevant 430 foo64(mv) // escapes but it's an int so irrelevant
428 } 431 }
429 432
430 func foo69(m M) { // ERROR "leaking param: m" 433 func foo69(m M) { // ERROR "leaking param: m"
431 foo64(m) 434 foo64(m)
432 } 435 }
433 436
434 func foo70(mv1 *MV, m M) { // ERROR "leaking param: mv1" "leaking param: m" 437 func foo70(mv1 *MV, m M) { // ERROR "leaking param: mv1" "leaking param: m"
435 m = mv1 438 m = mv1
436 foo64(m) 439 foo64(m)
437 } 440 }
438 441
439 func foo71(x *int) []*int { // ERROR "leaking param: x" 442 func foo71(x *int) []*int { // ERROR "leaking param: x"
440 var y []*int 443 var y []*int
441 y = append(y, x) 444 y = append(y, x)
442 return y 445 return y
443 } 446 }
444 447
445 func foo71a(x int) []*int { // ERROR "moved to heap: x" 448 func foo71a(x int) []*int { // ERROR "moved to heap: x"
446 var y []*int 449 var y []*int
447 » y = append(y, &x) // ERROR "&x escapes to heap" 450 » y = append(y, &x) // ERROR "&x escapes to heap"
448 return y 451 return y
449 } 452 }
450 453
451 func foo72() { 454 func foo72() {
452 var x int 455 var x int
453 var y [1]*int 456 var y [1]*int
454 » y[0] = &x // ERROR "&x does not escape" 457 » y[0] = &x // ERROR "&x does not escape"
455 } 458 }
456 459
457 func foo72aa() [10]*int { 460 func foo72aa() [10]*int {
458 var x int // ERROR "moved to heap: x" 461 var x int // ERROR "moved to heap: x"
459 var y [10]*int 462 var y [10]*int
460 » y[0] = &x // ERROR "&x escapes to heap" 463 » y[0] = &x // ERROR "&x escapes to heap"
461 return y 464 return y
462 } 465 }
463 466
464 func foo72a() { 467 func foo72a() {
465 var y [10]*int 468 var y [10]*int
466 for i := 0; i < 10; i++ { 469 for i := 0; i < 10; i++ {
467 // escapes its scope 470 // escapes its scope
468 » » x := i // ERROR "moved to heap: x" 471 » » x := i // ERROR "moved to heap: x"
469 y[i] = &x // ERROR "&x escapes to heap" 472 y[i] = &x // ERROR "&x escapes to heap"
470 } 473 }
471 return 474 return
472 } 475 }
473 476
474 func foo72b() [10]*int { 477 func foo72b() [10]*int {
475 var y [10]*int 478 var y [10]*int
476 for i := 0; i < 10; i++ { 479 for i := 0; i < 10; i++ {
477 » » x := i // ERROR "moved to heap: x" 480 » » x := i // ERROR "moved to heap: x"
478 » » y[i] = &x // ERROR "&x escapes to heap" 481 » » y[i] = &x // ERROR "&x escapes to heap"
479 } 482 }
480 return y 483 return y
481 } 484 }
482 485
483 // issue 2145 486 // issue 2145
484 func foo73() { 487 func foo73() {
485 s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape" 488 s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape"
486 for _, v := range s { 489 for _, v := range s {
487 » » vv := v // ERROR "moved to heap: vv" 490 » » vv := v // ERROR "moved to heap: vv"
488 // actually just escapes its scope 491 // actually just escapes its scope
489 defer func() { // ERROR "func literal escapes to heap" 492 defer func() { // ERROR "func literal escapes to heap"
490 » » » println(vv) // ERROR "&vv escapes to heap" 493 » » » println(vv) // ERROR "&vv escapes to heap"
491 }() 494 }()
492 } 495 }
493 } 496 }
494 497
495 func foo74() { 498 func foo74() {
496 s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape" 499 s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape"
497 for _, v := range s { 500 for _, v := range s {
498 » » vv := v // ERROR "moved to heap: vv" 501 » » vv := v // ERROR "moved to heap: vv"
499 // actually just escapes its scope 502 // actually just escapes its scope
500 fn := func() { // ERROR "func literal escapes to heap" 503 fn := func() { // ERROR "func literal escapes to heap"
501 » » » println(vv) // ERROR "&vv escapes to heap" 504 » » » println(vv) // ERROR "&vv escapes to heap"
502 } 505 }
503 defer fn() 506 defer fn()
504 } 507 }
505 } 508 }
506 509
507 func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leak ing param: y" 510 func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leak ing param: y"
508 return y 511 return y
509 } 512 }
510 513
511 func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not esca pe" "leaking param: x" 514 func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not esca pe" "leaking param: x"
512 » return &x[0] // ERROR "&x.0. escapes to heap" 515 » return &x[0] // ERROR "&x.0. escapes to heap"
513 } 516 }
514 517
515 func foo75(z *int) { // ERROR "leaking param: z" 518 func foo75(z *int) { // ERROR "leaking param: z"
516 myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" 519 myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape"
517 } 520 }
518 521
519 func foo75a(z *int) { // ERROR "z does not escape" 522 func foo75a(z *int) { // ERROR "z does not escape"
520 myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" 523 myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
521 } 524 }
522 525
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 562
560 func foo77(z []interface{}) { // ERROR "z does not escape" 563 func foo77(z []interface{}) { // ERROR "z does not escape"
561 myprint(nil, z...) // z does not escape 564 myprint(nil, z...) // z does not escape
562 } 565 }
563 566
564 func foo77a(z []interface{}) { // ERROR "leaking param: z" 567 func foo77a(z []interface{}) { // ERROR "leaking param: z"
565 myprint1(nil, z...) 568 myprint1(nil, z...)
566 } 569 }
567 570
568 func foo78(z int) *int { // ERROR "moved to heap: z" 571 func foo78(z int) *int { // ERROR "moved to heap: z"
569 » return &z // ERROR "&z escapes to heap" 572 » return &z // ERROR "&z escapes to heap"
570 } 573 }
571 574
572 func foo78a(z int) *int { // ERROR "moved to heap: z" 575 func foo78a(z int) *int { // ERROR "moved to heap: z"
573 » y := &z // ERROR "&z escapes to heap" 576 » y := &z // ERROR "&z escapes to heap"
574 » x := &y // ERROR "&y does not escape" 577 » x := &y // ERROR "&y does not escape"
575 return *x // really return y 578 return *x // really return y
576 } 579 }
577 580
578 func foo79() *int { 581 func foo79() *int {
579 return new(int) // ERROR "new[(]int[)] escapes to heap" 582 return new(int) // ERROR "new[(]int[)] escapes to heap"
580 } 583 }
581 584
582 func foo80() *int { 585 func foo80() *int {
583 var z *int 586 var z *int
584 for { 587 for {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 func foo101(m [1]*int) *int { // ERROR "leaking param: m" 681 func foo101(m [1]*int) *int { // ERROR "leaking param: m"
679 for _, v := range m { 682 for _, v := range m {
680 return v 683 return v
681 } 684 }
682 return nil 685 return nil
683 } 686 }
684 687
685 // does not leak m 688 // does not leak m
686 func foo101a(m [1]*int) *int { // ERROR "m does not escape" 689 func foo101a(m [1]*int) *int { // ERROR "m does not escape"
687 for i := range m { // ERROR "moved to heap: i" 690 for i := range m { // ERROR "moved to heap: i"
688 » » return &i // ERROR "&i escapes to heap" 691 » » return &i // ERROR "&i escapes to heap"
689 } 692 }
690 return nil 693 return nil
691 } 694 }
692 695
693 // does leak x 696 // does leak x
694 func foo102(m []*int, x *int) { // ERROR "m does not escape" "leaking param: x" 697 func foo102(m []*int, x *int) { // ERROR "m does not escape" "leaking param: x"
695 m[0] = x 698 m[0] = x
696 } 699 }
697 700
698 // does not leak x 701 // does not leak x
699 func foo103(m [1]*int, x *int) { // ERROR "m does not escape" "x does not escape " 702 func foo103(m [1]*int, x *int) { // ERROR "m does not escape" "x does not escape "
700 m[0] = x 703 m[0] = x
701 } 704 }
702 705
703 var y []*int 706 var y []*int
704 707
705 // does not leak x 708 // does not leak x
706 func foo104(x []*int) { // ERROR "x does not escape" 709 func foo104(x []*int) { // ERROR "x does not escape"
707 copy(y, x) 710 copy(y, x)
708 } 711 }
709 712
710 // does not leak x 713 // does not leak x
711 func foo105(x []*int) { // ERROR "x does not escape" 714 func foo105(x []*int) { // ERROR "x does not escape"
712 _ = append(y, x...) 715 _ = append(y, x...)
713 } 716 }
714 717
715 // does leak x 718 // does leak x
716 func foo106(x *int) { // ERROR "leaking param: x" 719 func foo106(x *int) { // ERROR "leaking param: x"
717 _ = append(y, x) 720 _ = append(y, x)
718 } 721 }
719 722
720 func foo107(x *int) map[*int]*int { // ERROR "leaking param: x" 723 func foo107(x *int) map[*int]*int { // ERROR "leaking param: x"
721 return map[*int]*int{x: nil} // ERROR "map.* literal escapes to heap" 724 return map[*int]*int{x: nil} // ERROR "map.* literal escapes to heap"
722 } 725 }
723 726
724 func foo108(x *int) map[*int]*int { // ERROR "leaking param: x" 727 func foo108(x *int) map[*int]*int { // ERROR "leaking param: x"
725 return map[*int]*int{nil: x} // ERROR "map.* literal escapes to heap" 728 return map[*int]*int{nil: x} // ERROR "map.* literal escapes to heap"
726 } 729 }
727 730
728 func foo109(x *int) *int { // ERROR "leaking param: x" 731 func foo109(x *int) *int { // ERROR "leaking param: x"
729 » m := map[*int]*int{x: nil} // ERROR "map.* literal does not escape" 732 » m := map[*int]*int{x: nil} // ERROR "map.* literal does not escape"
730 for k, _ := range m { 733 for k, _ := range m {
731 return k 734 return k
732 } 735 }
733 return nil 736 return nil
734 } 737 }
735 738
736 func foo110(x *int) *int { // ERROR "leaking param: x" 739 func foo110(x *int) *int { // ERROR "leaking param: x"
737 » m := map[*int]*int{nil: x} // ERROR "map.* literal does not escape" 740 » m := map[*int]*int{nil: x} // ERROR "map.* literal does not escape"
738 return m[nil] 741 return m[nil]
739 } 742 }
740 743
741 func foo111(x *int) *int { // ERROR "leaking param: x" 744 func foo111(x *int) *int { // ERROR "leaking param: x"
742 » m := []*int{x} // ERROR "\[\]\*int literal does not escape" 745 » m := []*int{x} // ERROR "\[\]\*int literal does not escape"
743 return m[0] 746 return m[0]
744 } 747 }
745 748
746 func foo112(x *int) *int { // ERROR "leaking param: x" 749 func foo112(x *int) *int { // ERROR "leaking param: x"
747 m := [1]*int{x} 750 m := [1]*int{x}
748 return m[0] 751 return m[0]
749 } 752 }
750 753
751 func foo113(x *int) *int { // ERROR "leaking param: x" 754 func foo113(x *int) *int { // ERROR "leaking param: x"
752 m := Bar{ii: x} 755 m := Bar{ii: x}
753 return m.ii 756 return m.ii
754 } 757 }
755 758
756 func foo114(x *int) *int { // ERROR "leaking param: x" 759 func foo114(x *int) *int { // ERROR "leaking param: x"
757 » m := &Bar{ii: x} // ERROR "&Bar literal does not escape" 760 » m := &Bar{ii: x} // ERROR "&Bar literal does not escape"
758 return m.ii 761 return m.ii
759 } 762 }
760 763
761 func foo115(x *int) *int { // ERROR "leaking param: x" 764 func foo115(x *int) *int { // ERROR "leaking param: x"
762 return (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + 1)) 765 return (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + 1))
763 } 766 }
764 767
765 func foo116(b bool) *int { 768 func foo116(b bool) *int {
766 if b { 769 if b {
767 » » x := 1 // ERROR "moved to heap: x" 770 » » x := 1 // ERROR "moved to heap: x"
768 » » return &x // ERROR "&x escapes to heap" 771 » » return &x // ERROR "&x escapes to heap"
769 } else { 772 } else {
770 » » y := 1 // ERROR "moved to heap: y" 773 » » y := 1 // ERROR "moved to heap: y"
771 » » return &y // ERROR "&y escapes to heap" 774 » » return &y // ERROR "&y escapes to heap"
772 » } 775 » }
773 » return nil 776 » return nil
774 } 777 }
775 778
776 func foo117(unknown func(interface{})) { // ERROR "unknown does not escape" 779 func foo117(unknown func(interface{})) { // ERROR "unknown does not escape"
777 » x := 1 // ERROR "moved to heap: x" 780 » x := 1 // ERROR "moved to heap: x"
778 unknown(&x) // ERROR "&x escapes to heap" 781 unknown(&x) // ERROR "&x escapes to heap"
779 } 782 }
780 783
781 func foo118(unknown func(*int)) { // ERROR "unknown does not escape" 784 func foo118(unknown func(*int)) { // ERROR "unknown does not escape"
782 » x := 1 // ERROR "moved to heap: x" 785 » x := 1 // ERROR "moved to heap: x"
783 unknown(&x) // ERROR "&x escapes to heap" 786 unknown(&x) // ERROR "&x escapes to heap"
784 } 787 }
785 788
786 func external(*int) 789 func external(*int)
787 790
788 func foo119(x *int) { // ERROR "leaking param: x" 791 func foo119(x *int) { // ERROR "leaking param: x"
789 external(x) 792 external(x)
790 } 793 }
791 794
792 func foo120() { 795 func foo120() {
793 // formerly exponential time analysis 796 // formerly exponential time analysis
794 L1: 797 L1:
795 L2: 798 L2:
796 L3: 799 L3:
797 L4: 800 L4:
798 L5: 801 L5:
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 goto L92 989 goto L92
987 goto L93 990 goto L93
988 goto L94 991 goto L94
989 goto L95 992 goto L95
990 goto L96 993 goto L96
991 goto L97 994 goto L97
992 goto L98 995 goto L98
993 goto L99 996 goto L99
994 goto L100 997 goto L100
995 } 998 }
999
1000 func foo121() {
1001 for i := 0; i < 10; i++ {
1002 defer myprint(nil, i) // ERROR "[.][.][.] argument escapes to he ap"
1003 go myprint(nil, i) // ERROR "[.][.][.] argument escapes to he ap"
1004 }
1005 }
1006
1007 // same as foo121 but check across import
1008 func foo121b() {
1009 for i := 0; i < 10; i++ {
1010 defer fmt.Printf("%d", i) // ERROR "[.][.][.] argument escapes t o heap"
1011 go fmt.Printf("%d", i) // ERROR "[.][.][.] argument escapes t o heap"
1012 }
1013 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b