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.
7 // Test, using compiler diagnostic flags, that the escape analysis is working.
8 // Compiles but does not run. Inlining is enabled.
14 func alloc(x int) *int { // ERROR "can inline alloc" "moved to heap: x"
21 p = alloc(2) // ERROR "inlining call to alloc" "moved to heap: x"
23 // Escape analysis used to miss inlined code in closures.
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"
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"
35 func f2() {} // ERROR "can inline f2"
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() }
41 func f5() *byte { // ERROR "can inline f5"
45 t := new(T) // ERROR "new.T. escapes to heap"
49 func f6() *byte { // ERROR "can inline f6"
55 t := new(T) // ERROR "new.T. escapes to heap"