]> Cypherpunks.ru repositories - gostls13.git/blob - test/escape4.go
test: skip inlining check in escape4.go
[gostls13.git] / test / escape4.go
1 // errorcheck -0 -m
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 // Test, using compiler diagnostic flags, that the escape analysis is working.
8 // Compiles but does not run.  Inlining is enabled.
9
10 package foo
11
12 var p *int
13
14 func alloc(x int) *int { // ERROR "can inline alloc" "moved to heap: x"
15         return &x
16 }
17
18 var f func()
19
20 func f1() {
21         p = alloc(2) // ERROR "inlining call to alloc" "moved to heap: x"
22
23         // Escape analysis used to miss inlined code in closures.
24
25         func() { // ERROR "can inline f1.func1"
26                 p = alloc(3) // ERROR "inlining call to alloc"
27         }() // ERROR "inlining call to f1.func1" "inlining call to alloc" "moved to heap: x"
28
29         f = func() { // ERROR "func literal escapes to heap" "can inline f1.func2"
30                 p = alloc(3) // ERROR "inlining call to alloc" "moved to heap: x"
31         }
32         f()
33 }
34
35 func f2() {} // ERROR "can inline f2"
36
37 // No inline for recover; panic now allowed to inline.
38 func f3() { panic(1) } // ERROR "can inline f3" "1 escapes to heap"
39 func f4() { recover() }
40
41 // TODO(cuonglm): remove f5, f6 //go:noinline and update the error message
42 //                once GOEXPERIMENT=nounified is gone.
43
44 //go:noinline
45 func f5() *byte {
46         type T struct {
47                 x [1]byte
48         }
49         t := new(T) // ERROR "new.T. escapes to heap"
50         return &t.x[0]
51 }
52
53 //go:noinline
54 func f6() *byte {
55         type T struct {
56                 x struct {
57                         y byte
58                 }
59         }
60         t := new(T) // ERROR "new.T. escapes to heap"
61         return &t.x.y
62 }