OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [escape2.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// errchk -0 $G -m -l $D/$F.go
2
 
3
// Copyright 2010 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.
6
 
7
package foo
8
 
9
import (
10
        "fmt"
11
        "unsafe"
12
)
13
 
14
var gxx *int
15
 
16
func foo1(x int) { // ERROR "moved to heap: x"
17
        gxx = &x // ERROR "&x escapes to heap"
18
}
19
 
20
func foo2(yy *int) { // ERROR "leaking param: yy"
21
        gxx = yy
22
}
23
 
24
func foo3(x int) *int { // ERROR "moved to heap: x"
25
        return &x // ERROR "&x escapes to heap"
26
}
27
 
28
type T *T
29
 
30
func foo3b(t T) { // ERROR "leaking param: t"
31
        *t = t
32
}
33
 
34
// xx isn't going anywhere, so use of yy is ok
35
func foo4(xx, yy *int) { // ERROR "xx does not escape" "yy does not escape"
36
        xx = yy
37
}
38
 
39
// xx isn't going anywhere, so taking address of yy is ok
40
func foo5(xx **int, yy *int) { // ERROR "xx does not escape" "yy does not escape"
41
        xx = &yy // ERROR "&yy does not escape"
42
}
43
 
44
func foo6(xx **int, yy *int) { // ERROR "xx does not escape" "leaking param: yy"
45
        *xx = yy
46
}
47
 
48
func foo7(xx **int, yy *int) { // ERROR "xx does not escape" "yy does not escape"
49
        **xx = *yy
50
}
51
 
52
func foo8(xx, yy *int) int { // ERROR "xx does not escape" "yy does not escape"
53
        xx = yy
54
        return *xx
55
}
56
 
57
func foo9(xx, yy *int) *int { // ERROR "leaking param: xx" "leaking param: yy"
58
        xx = yy
59
        return xx
60
}
61
 
62
func foo10(xx, yy *int) { // ERROR "xx does not escape" "yy does not escape"
63
        *xx = *yy
64
}
65
 
66
func foo11() int {
67
        x, y := 0, 42
68
        xx := &x // ERROR "&x does not escape"
69
        yy := &y // ERROR "&y does not escape"
70
        *xx = *yy
71
        return x
72
}
73
 
74
var xxx **int
75
 
76
func foo12(yyy **int) { // ERROR "leaking param: yyy"
77
        xxx = yyy
78
}
79
 
80
func foo13(yyy **int) { // ERROR "yyy does not escape"
81
        *xxx = *yyy
82
}
83
 
84
func foo14(yyy **int) { // ERROR "yyy does not escape"
85
        **xxx = **yyy
86
}
87
 
88
func foo15(yy *int) { // ERROR "moved to heap: yy"
89
        xxx = &yy // ERROR "&yy escapes to heap"
90
}
91
 
92
func foo16(yy *int) { // ERROR "leaking param: yy"
93
        *xxx = yy
94
}
95
 
96
func foo17(yy *int) { // ERROR "yy does not escape"
97
        **xxx = *yy
98
}
99
 
100
func foo18(y int) { // ERROR "moved to heap: "y"
101
        *xxx = &y // ERROR "&y escapes to heap"
102
}
103
 
104
func foo19(y int) {
105
        **xxx = y
106
}
107
 
108
type Bar struct {
109
        i  int
110
        ii *int
111
}
112
 
113
func NewBar() *Bar {
114
        return &Bar{42, nil} // ERROR "&Bar literal escapes to heap"
115
}
116
 
117
func NewBarp(x *int) *Bar { // ERROR "leaking param: x"
118
        return &Bar{42, x} // ERROR "&Bar literal escapes to heap"
119
}
120
 
121
func NewBarp2(x *int) *Bar { // ERROR "x does not escape"
122
        return &Bar{*x, nil} // ERROR "&Bar literal escapes to heap"
123
}
124
 
125
func (b *Bar) NoLeak() int { // ERROR "b does not escape"
126
        return *(b.ii)
127
}
128
 
129
func (b *Bar) Leak() *int { // ERROR "leaking param: b"
130
        return &b.i // ERROR "&b.i escapes to heap"
131
}
132
 
133
func (b *Bar) AlsoNoLeak() *int { // ERROR "b does not escape"
134
        return b.ii
135
}
136
 
137
func (b Bar) AlsoLeak() *int { // ERROR "leaking param: b"
138
        return b.ii
139
}
140
 
141
func (b Bar) LeaksToo() *int { // ERROR "leaking param: b"
142
        v := 0  // ERROR "moved to heap: v"
143
        b.ii = &v // ERROR "&v escapes"
144
        return b.ii
145
}
146
 
147
func (b *Bar) LeaksABit() *int { // ERROR "b does not escape"
148
        v := 0  // ERROR "moved to heap: v"
149
        b.ii = &v // ERROR "&v escapes"
150
        return b.ii
151
}
152
 
153
func (b Bar) StillNoLeak() int { // ERROR "b does not escape"
154
        v := 0
155
        b.ii = &v // ERROR "&v does not escape"
156
        return b.i
157
}
158
 
159
func goLeak(b *Bar) { // ERROR "leaking param: b"
160
        go b.NoLeak()
161
}
162
 
163
type Bar2 struct {
164
        i  [12]int
165
        ii []int
166
}
167
 
168
func NewBar2() *Bar2 {
169
        return &Bar2{[12]int{42}, nil} // ERROR "&Bar2 literal escapes to heap"
170
}
171
 
172
func (b *Bar2) NoLeak() int { // ERROR "b does not escape"
173
        return b.i[0]
174
}
175
 
176
func (b *Bar2) Leak() []int { // ERROR "leaking param: b"
177
        return b.i[:] // ERROR "b.i escapes to heap"
178
}
179
 
180
func (b *Bar2) AlsoNoLeak() []int { // ERROR "b does not escape"
181
        return b.ii[0:1]
182
}
183
 
184
func (b Bar2) AgainNoLeak() [12]int { // ERROR "b does not escape"
185
        return b.i
186
}
187
 
188
func (b *Bar2) LeakSelf() { // ERROR "leaking param: b"
189
        b.ii = b.i[0:4] // ERROR "b.i escapes to heap"
190
}
191
 
192
func (b *Bar2) LeakSelf2() { // ERROR "leaking param: b"
193
        var buf []int
194
        buf = b.i[0:] // ERROR "b.i escapes to heap"
195
        b.ii = buf
196
}
197
 
198
func foo21() func() int {
199
        x := 42             // ERROR "moved to heap: x"
200
        return func() int { // ERROR "func literal escapes to heap"
201
                return x // ERROR "&x escapes to heap"
202
        }
203
}
204
 
205
func foo22() int {
206
        x := 42
207
        return func() int { // ERROR "func literal does not escape"
208
                return x
209
        }()
210
}
211
 
212
func foo23(x int) func() int { // ERROR "moved to heap: x"
213
        return func() int { // ERROR "func literal escapes to heap"
214
                return x // ERROR "&x escapes to heap"
215
        }
216
}
217
 
218
func foo23a(x int) func() int { // ERROR "moved to heap: x"
219
        f := func() int { // ERROR "func literal escapes to heap"
220
                return x // ERROR "&x escapes to heap"
221
        }
222
        return f
223
}
224
 
225
func foo23b(x int) *(func() int) { // ERROR "moved to heap: x"
226
        f := func() int { return x } // ERROR "moved to heap: f" "func literal escapes to heap" "&x escapes to heap"
227
        return &f                    // ERROR "&f escapes to heap"
228
}
229
 
230
func foo24(x int) int {
231
        return func() int { // ERROR "func literal does not escape"
232
                return x
233
        }()
234
}
235
 
236
var x *int
237
 
238
func fooleak(xx *int) int { // ERROR "leaking param: xx"
239
        x = xx
240
        return *x
241
}
242
 
243
func foonoleak(xx *int) int { // ERROR "xx does not escape"
244
        return *x + *xx
245
}
246
 
247
func foo31(x int) int { // ERROR "moved to heap: x"
248
        return fooleak(&x) // ERROR "&x escapes to heap"
249
}
250
 
251
func foo32(x int) int {
252
        return foonoleak(&x) // ERROR "&x does not escape"
253
}
254
 
255
type Foo struct {
256
        xx *int
257
        x  int
258
}
259
 
260
var F Foo
261
var pf *Foo
262
 
263
func (f *Foo) fooleak() { // ERROR "leaking param: f"
264
        pf = f
265
}
266
 
267
func (f *Foo) foonoleak() { // ERROR "f does not escape"
268
        F.x = f.x
269
}
270
 
271
func (f *Foo) Leak() { // ERROR "leaking param: f"
272
        f.fooleak()
273
}
274
 
275
func (f *Foo) NoLeak() { // ERROR "f does not escape"
276
        f.foonoleak()
277
}
278
 
279
func foo41(x int) { // ERROR "moved to heap: x"
280
        F.xx = &x // ERROR "&x escapes to heap"
281
}
282
 
283
func (f *Foo) foo42(x int) { // ERROR "f does not escape" "moved to heap: x"
284
        f.xx = &x // ERROR "&x escapes to heap"
285
}
286
 
287
func foo43(f *Foo, x int) { // ERROR "f does not escape" "moved to heap: x"
288
        f.xx = &x // ERROR "&x escapes to heap"
289
}
290
 
291
func foo44(yy *int) { // ERROR "leaking param: yy"
292
        F.xx = yy
293
}
294
 
295
func (f *Foo) foo45() { // ERROR "f does not escape"
296
        F.x = f.x
297
}
298
 
299
func (f *Foo) foo46() { // ERROR "f does not escape"
300
        F.xx = f.xx
301
}
302
 
303
func (f *Foo) foo47() { // ERROR "leaking param: f"
304
        f.xx = &f.x // ERROR "&f.x escapes to heap"
305
}
306
 
307
var ptrSlice []*int
308
 
309
func foo50(i *int) { // ERROR "leaking param: i"
310
        ptrSlice[0] = i
311
}
312
 
313
var ptrMap map[*int]*int
314
 
315
func foo51(i *int) { // ERROR "leaking param: i"
316
        ptrMap[i] = i
317
}
318
 
319
func indaddr1(x int) *int { // ERROR "moved to heap: x"
320
        return &x // ERROR "&x escapes to heap"
321
}
322
 
323
func indaddr2(x *int) *int { // ERROR "leaking param: x"
324
        return *&x // ERROR "&x does not escape"
325
}
326
 
327
func indaddr3(x *int32) *int { // ERROR "leaking param: x"
328
        return *(**int)(unsafe.Pointer(&x)) // ERROR "&x does not escape"
329
}
330
 
331
// From package math:
332
 
333
func Float32bits(f float32) uint32 {
334
        return *(*uint32)(unsafe.Pointer(&f)) // ERROR "&f does not escape"
335
}
336
 
337
func Float32frombits(b uint32) float32 {
338
        return *(*float32)(unsafe.Pointer(&b)) // ERROR "&b does not escape"
339
}
340
 
341
func Float64bits(f float64) uint64 {
342
        return *(*uint64)(unsafe.Pointer(&f)) // ERROR "&f does not escape"
343
}
344
 
345
func Float64frombits(b uint64) float64 {
346
        return *(*float64)(unsafe.Pointer(&b)) // ERROR "&b does not escape"
347
}
348
 
349
// contrast with
350
func float64bitsptr(f float64) *uint64 { // ERROR "moved to heap: f"
351
        return (*uint64)(unsafe.Pointer(&f)) // ERROR "&f escapes to heap"
352
}
353
 
354
func float64ptrbitsptr(f *float64) *uint64 { // ERROR "leaking param: f"
355
        return (*uint64)(unsafe.Pointer(f))
356
}
357
 
358
func typesw(i interface{}) *int { // ERROR "leaking param: i"
359
        switch val := i.(type) {
360
        case *int:
361
                return val
362
        case *int8:
363
                v := int(*val) // ERROR "moved to heap: v"
364
                return &v      // ERROR "&v escapes to heap"
365
        }
366
        return nil
367
}
368
 
369
func exprsw(i *int) *int { // ERROR "leaking param: i"
370
        switch j := i; *j + 110 {
371
        case 12:
372
                return j
373
        case 42:
374
                return nil
375
        }
376
        return nil
377
 
378
}
379
 
380
// assigning to an array element is like assigning to the array
381
func foo60(i *int) *int { // ERROR "leaking param: i"
382
        var a [12]*int
383
        a[0] = i
384
        return a[1]
385
}
386
 
387
func foo60a(i *int) *int { // ERROR "i does not escape"
388
        var a [12]*int
389
        a[0] = i
390
        return nil
391
}
392
 
393
// assigning to a struct field  is like assigning to the struct
394
func foo61(i *int) *int { // ERROR "leaking param: i"
395
        type S struct {
396
                a, b *int
397
        }
398
        var s S
399
        s.a = i
400
        return s.b
401
}
402
 
403
func foo61a(i *int) *int { // ERROR "i does not escape"
404
        type S struct {
405
                a, b *int
406
        }
407
        var s S
408
        s.a = i
409
        return nil
410
}
411
 
412
// assigning to a struct field is like assigning to the struct but
413
// here this subtlety is lost, since s.a counts as an assignment to a
414
// track-losing dereference.
415
func foo62(i *int) *int { // ERROR "leaking param: i"
416
        type S struct {
417
                a, b *int
418
        }
419
        s := new(S) // ERROR "new[(]S[)] does not escape"
420
        s.a = i
421
        return nil // s.b
422
}
423
 
424
type M interface {
425
        M()
426
}
427
 
428
func foo63(m M) { // ERROR "m does not escape"
429
}
430
 
431
func foo64(m M) { // ERROR "leaking param: m"
432
        m.M()
433
}
434
 
435
func foo64b(m M) { // ERROR "leaking param: m"
436
        defer m.M()
437
}
438
 
439
type MV int
440
 
441
func (MV) M() {}
442
 
443
func foo65() {
444
        var mv MV
445
        foo63(&mv) // ERROR "&mv does not escape"
446
}
447
 
448
func foo66() {
449
        var mv MV  // ERROR "moved to heap: mv"
450
        foo64(&mv) // ERROR "&mv escapes to heap"
451
}
452
 
453
func foo67() {
454
        var mv MV
455
        foo63(mv)
456
}
457
 
458
func foo68() {
459
        var mv MV
460
        foo64(mv) // escapes but it's an int so irrelevant
461
}
462
 
463
func foo69(m M) { // ERROR "leaking param: m"
464
        foo64(m)
465
}
466
 
467
func foo70(mv1 *MV, m M) { // ERROR "leaking param: mv1" "leaking param: m"
468
        m = mv1
469
        foo64(m)
470
}
471
 
472
func foo71(x *int) []*int { // ERROR "leaking param: x"
473
        var y []*int
474
        y = append(y, x)
475
        return y
476
}
477
 
478
func foo71a(x int) []*int { // ERROR "moved to heap: x"
479
        var y []*int
480
        y = append(y, &x) // ERROR "&x escapes to heap"
481
        return y
482
}
483
 
484
func foo72() {
485
        var x int
486
        var y [1]*int
487
        y[0] = &x // ERROR "&x does not escape"
488
}
489
 
490
func foo72aa() [10]*int {
491
        var x int // ERROR "moved to heap: x"
492
        var y [10]*int
493
        y[0] = &x // ERROR "&x escapes to heap"
494
        return y
495
}
496
 
497
func foo72a() {
498
        var y [10]*int
499
        for i := 0; i < 10; i++ {
500
                // escapes its scope
501
                x := i    // ERROR "moved to heap: x"
502
                y[i] = &x // ERROR "&x escapes to heap"
503
        }
504
        return
505
}
506
 
507
func foo72b() [10]*int {
508
        var y [10]*int
509
        for i := 0; i < 10; i++ {
510
                x := i    // ERROR "moved to heap: x"
511
                y[i] = &x // ERROR "&x escapes to heap"
512
        }
513
        return y
514
}
515
 
516
// issue 2145
517
func foo73() {
518
        s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape"
519
        for _, v := range s {
520
                vv := v // ERROR "moved to heap: vv"
521
                // actually just escapes its scope
522
                defer func() { // ERROR "func literal escapes to heap"
523
                        println(vv) // ERROR "&vv escapes to heap"
524
                }()
525
        }
526
}
527
 
528
func foo74() {
529
        s := []int{3, 2, 1} // ERROR "\[\]int literal does not escape"
530
        for _, v := range s {
531
                vv := v // ERROR "moved to heap: vv"
532
                // actually just escapes its scope
533
                fn := func() { // ERROR "func literal escapes to heap"
534
                        println(vv) // ERROR "&vv escapes to heap"
535
                }
536
                defer fn()
537
        }
538
}
539
 
540
func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leaking param: y"
541
        return y
542
}
543
 
544
func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not escape" "leaking param: x"
545
        return &x[0] // ERROR "&x.0. escapes to heap"
546
}
547
 
548
func foo75(z *int) { // ERROR "leaking param: z"
549
        myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape"
550
}
551
 
552
func foo75a(z *int) { // ERROR "z does not escape"
553
        myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
554
}
555
 
556
func foo76(z *int) { // ERROR "leaking param: z"
557
        myprint(nil, z) // ERROR "[.][.][.] argument does not escape"
558
}
559
 
560
func foo76a(z *int) { // ERROR "leaking param: z"
561
        myprint1(nil, z) // ERROR "[.][.][.] argument escapes to heap"
562
}
563
 
564
func foo76b() {
565
        myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape"
566
}
567
 
568
func foo76c() {
569
        myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
570
}
571
 
572
func foo76d() {
573
        defer myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape"
574
}
575
 
576
func foo76e() {
577
        defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
578
}
579
 
580
func foo76f() {
581
        for {
582
                // TODO: This one really only escapes its scope, but we don't distinguish yet.
583
                defer myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
584
        }
585
}
586
 
587
func foo76g() {
588
        for {
589
                defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
590
        }
591
}
592
 
593
func foo77(z []interface{}) { // ERROR "z does not escape"
594
        myprint(nil, z...) // z does not escape
595
}
596
 
597
func foo77a(z []interface{}) { // ERROR "leaking param: z"
598
        myprint1(nil, z...)
599
}
600
 
601
func foo78(z int) *int { // ERROR "moved to heap: z"
602
        return &z // ERROR "&z escapes to heap"
603
}
604
 
605
func foo78a(z int) *int { // ERROR "moved to heap: z"
606
        y := &z   // ERROR "&z escapes to heap"
607
        x := &y   // ERROR "&y does not escape"
608
        return *x // really return y
609
}
610
 
611
func foo79() *int {
612
        return new(int) // ERROR "new[(]int[)] escapes to heap"
613
}
614
 
615
func foo80() *int {
616
        var z *int
617
        for {
618
                // Really just escapes its scope but we don't distinguish
619
                z = new(int) // ERROR "new[(]int[)] escapes to heap"
620
        }
621
        _ = z
622
        return nil
623
}
624
 
625
func foo81() *int {
626
        for {
627
                z := new(int) // ERROR "new[(]int[)] does not escape"
628
                _ = z
629
        }
630
        return nil
631
}
632
 
633
type Fooer interface {
634
        Foo()
635
}
636
 
637
type LimitedFooer struct {
638
        Fooer
639
        N int64
640
}
641
 
642
func LimitFooer(r Fooer, n int64) Fooer { // ERROR "leaking param: r"
643
        return &LimitedFooer{r, n} // ERROR "&LimitedFooer literal escapes to heap"
644
}
645
 
646
func foo90(x *int) map[*int]*int { // ERROR "leaking param: x"
647
        return map[*int]*int{nil: x} // ERROR "map\[\*int\]\*int literal escapes to heap"
648
}
649
 
650
func foo91(x *int) map[*int]*int { // ERROR "leaking param: x"
651
        return map[*int]*int{x: nil} // ERROR "map\[\*int\]\*int literal escapes to heap"
652
}
653
 
654
func foo92(x *int) [2]*int { // ERROR "leaking param: x"
655
        return [2]*int{x, nil}
656
}
657
 
658
// does not leak c
659
func foo93(c chan *int) *int { // ERROR "c does not escape"
660
        for v := range c {
661
                return v
662
        }
663
        return nil
664
}
665
 
666
// does not leak m
667
func foo94(m map[*int]*int, b bool) *int { // ERROR "m does not escape"
668
        for k, v := range m {
669
                if b {
670
                        return k
671
                }
672
                return v
673
        }
674
        return nil
675
}
676
 
677
// does leak x
678
func foo95(m map[*int]*int, x *int) { // ERROR "m does not escape" "leaking param: x"
679
        m[x] = x
680
}
681
 
682
// does not leak m
683
func foo96(m []*int) *int { // ERROR "m does not escape"
684
        return m[0]
685
}
686
 
687
// does leak m
688
func foo97(m [1]*int) *int { // ERROR "leaking param: m"
689
        return m[0]
690
}
691
 
692
// does not leak m
693
func foo98(m map[int]*int) *int { // ERROR "m does not escape"
694
        return m[0]
695
}
696
 
697
// does leak m
698
func foo99(m *[1]*int) []*int { // ERROR "leaking param: m"
699
        return m[:]
700
}
701
 
702
// does not leak m
703
func foo100(m []*int) *int { // ERROR "m does not escape"
704
        for _, v := range m {
705
                return v
706
        }
707
        return nil
708
}
709
 
710
// does leak m
711
func foo101(m [1]*int) *int { // ERROR "leaking param: m"
712
        for _, v := range m {
713
                return v
714
        }
715
        return nil
716
}
717
 
718
// does not leak m
719
func foo101a(m [1]*int) *int { // ERROR "m does not escape"
720
        for i := range m { // ERROR "moved to heap: i"
721
                return &i // ERROR "&i escapes to heap"
722
        }
723
        return nil
724
}
725
 
726
// does leak x
727
func foo102(m []*int, x *int) { // ERROR "m does not escape" "leaking param: x"
728
        m[0] = x
729
}
730
 
731
// does not leak x
732
func foo103(m [1]*int, x *int) { // ERROR "m does not escape" "x does not escape"
733
        m[0] = x
734
}
735
 
736
var y []*int
737
 
738
// does not leak x
739
func foo104(x []*int) { // ERROR "x does not escape"
740
        copy(y, x)
741
}
742
 
743
// does not leak x
744
func foo105(x []*int) { // ERROR "x does not escape"
745
        _ = append(y, x...)
746
}
747
 
748
// does leak x
749
func foo106(x *int) { // ERROR "leaking param: x"
750
        _ = append(y, x)
751
}
752
 
753
func foo107(x *int) map[*int]*int { // ERROR "leaking param: x"
754
        return map[*int]*int{x: nil} // ERROR "map.* literal escapes to heap"
755
}
756
 
757
func foo108(x *int) map[*int]*int { // ERROR "leaking param: x"
758
        return map[*int]*int{nil: x} // ERROR "map.* literal escapes to heap"
759
}
760
 
761
func foo109(x *int) *int { // ERROR "leaking param: x"
762
        m := map[*int]*int{x: nil} // ERROR "map.* literal does not escape"
763
        for k, _ := range m {
764
                return k
765
        }
766
        return nil
767
}
768
 
769
func foo110(x *int) *int { // ERROR "leaking param: x"
770
        m := map[*int]*int{nil: x} // ERROR "map.* literal does not escape"
771
        return m[nil]
772
}
773
 
774
func foo111(x *int) *int { // ERROR "leaking param: x"
775
        m := []*int{x} // ERROR "\[\]\*int literal does not escape"
776
        return m[0]
777
}
778
 
779
func foo112(x *int) *int { // ERROR "leaking param: x"
780
        m := [1]*int{x}
781
        return m[0]
782
}
783
 
784
func foo113(x *int) *int { // ERROR "leaking param: x"
785
        m := Bar{ii: x}
786
        return m.ii
787
}
788
 
789
func foo114(x *int) *int { // ERROR "leaking param: x"
790
        m := &Bar{ii: x} // ERROR "&Bar literal does not escape"
791
        return m.ii
792
}
793
 
794
func foo115(x *int) *int { // ERROR "leaking param: x"
795
        return (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + 1))
796
}
797
 
798
func foo116(b bool) *int {
799
        if b {
800
                x := 1    // ERROR "moved to heap: x"
801
                return &x // ERROR "&x escapes to heap"
802
        } else {
803
                y := 1    // ERROR "moved to heap: y"
804
                return &y // ERROR "&y escapes to heap"
805
        }
806
        return nil
807
}
808
 
809
func foo117(unknown func(interface{})) { // ERROR "unknown does not escape"
810
        x := 1      // ERROR "moved to heap: x"
811
        unknown(&x) // ERROR "&x escapes to heap"
812
}
813
 
814
func foo118(unknown func(*int)) { // ERROR "unknown does not escape"
815
        x := 1      // ERROR "moved to heap: x"
816
        unknown(&x) // ERROR "&x escapes to heap"
817
}
818
 
819
func external(*int)
820
 
821
func foo119(x *int) { // ERROR "leaking param: x"
822
        external(x)
823
}
824
 
825
func foo120() {
826
        // formerly exponential time analysis
827
L1:
828
L2:
829
L3:
830
L4:
831
L5:
832
L6:
833
L7:
834
L8:
835
L9:
836
L10:
837
L11:
838
L12:
839
L13:
840
L14:
841
L15:
842
L16:
843
L17:
844
L18:
845
L19:
846
L20:
847
L21:
848
L22:
849
L23:
850
L24:
851
L25:
852
L26:
853
L27:
854
L28:
855
L29:
856
L30:
857
L31:
858
L32:
859
L33:
860
L34:
861
L35:
862
L36:
863
L37:
864
L38:
865
L39:
866
L40:
867
L41:
868
L42:
869
L43:
870
L44:
871
L45:
872
L46:
873
L47:
874
L48:
875
L49:
876
L50:
877
L51:
878
L52:
879
L53:
880
L54:
881
L55:
882
L56:
883
L57:
884
L58:
885
L59:
886
L60:
887
L61:
888
L62:
889
L63:
890
L64:
891
L65:
892
L66:
893
L67:
894
L68:
895
L69:
896
L70:
897
L71:
898
L72:
899
L73:
900
L74:
901
L75:
902
L76:
903
L77:
904
L78:
905
L79:
906
L80:
907
L81:
908
L82:
909
L83:
910
L84:
911
L85:
912
L86:
913
L87:
914
L88:
915
L89:
916
L90:
917
L91:
918
L92:
919
L93:
920
L94:
921
L95:
922
L96:
923
L97:
924
L98:
925
L99:
926
L100:
927
        // use the labels to silence compiler errors
928
        goto L1
929
        goto L2
930
        goto L3
931
        goto L4
932
        goto L5
933
        goto L6
934
        goto L7
935
        goto L8
936
        goto L9
937
        goto L10
938
        goto L11
939
        goto L12
940
        goto L13
941
        goto L14
942
        goto L15
943
        goto L16
944
        goto L17
945
        goto L18
946
        goto L19
947
        goto L20
948
        goto L21
949
        goto L22
950
        goto L23
951
        goto L24
952
        goto L25
953
        goto L26
954
        goto L27
955
        goto L28
956
        goto L29
957
        goto L30
958
        goto L31
959
        goto L32
960
        goto L33
961
        goto L34
962
        goto L35
963
        goto L36
964
        goto L37
965
        goto L38
966
        goto L39
967
        goto L40
968
        goto L41
969
        goto L42
970
        goto L43
971
        goto L44
972
        goto L45
973
        goto L46
974
        goto L47
975
        goto L48
976
        goto L49
977
        goto L50
978
        goto L51
979
        goto L52
980
        goto L53
981
        goto L54
982
        goto L55
983
        goto L56
984
        goto L57
985
        goto L58
986
        goto L59
987
        goto L60
988
        goto L61
989
        goto L62
990
        goto L63
991
        goto L64
992
        goto L65
993
        goto L66
994
        goto L67
995
        goto L68
996
        goto L69
997
        goto L70
998
        goto L71
999
        goto L72
1000
        goto L73
1001
        goto L74
1002
        goto L75
1003
        goto L76
1004
        goto L77
1005
        goto L78
1006
        goto L79
1007
        goto L80
1008
        goto L81
1009
        goto L82
1010
        goto L83
1011
        goto L84
1012
        goto L85
1013
        goto L86
1014
        goto L87
1015
        goto L88
1016
        goto L89
1017
        goto L90
1018
        goto L91
1019
        goto L92
1020
        goto L93
1021
        goto L94
1022
        goto L95
1023
        goto L96
1024
        goto L97
1025
        goto L98
1026
        goto L99
1027
        goto L100
1028
}
1029
 
1030
func foo121() {
1031
        for i := 0; i < 10; i++ {
1032
                defer myprint(nil, i) // ERROR "[.][.][.] argument escapes to heap"
1033
                go myprint(nil, i)    // ERROR "[.][.][.] argument escapes to heap"
1034
        }
1035
}
1036
 
1037
// same as foo121 but check across import
1038
func foo121b() {
1039
        for i := 0; i < 10; i++ {
1040
                defer fmt.Printf("%d", i) // ERROR "[.][.][.] argument escapes to heap"
1041
                go fmt.Printf("%d", i)    // ERROR "[.][.][.] argument escapes to heap"
1042
        }
1043
}
1044
 
1045
// a harmless forward jump
1046
func foo122() {
1047
        var i *int
1048
 
1049
        goto L1
1050
L1:
1051
        i = new(int) // ERROR "does not escape"
1052
        _ = i
1053
}
1054
 
1055
// a backward jump, increases loopdepth
1056
func foo123() {
1057
        var i *int
1058
 
1059
L1:
1060
        i = new(int) // ERROR "escapes"
1061
 
1062
        goto L1
1063
        _ = i
1064
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.