[AArch64] SVE tests
[official-gcc.git] / gcc / testsuite / go.test / test / escape4.go
blob83bc8eb123dd976c93d2dfb3fefc131fb56efde1
1 // errorcheck -0 -m
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.
10 package foo
12 var p *int
14 func alloc(x int) *int { // ERROR "can inline alloc" "moved to heap: x"
15 return &x // ERROR "&x escapes to heap"
18 var f func()
20 func f1() {
21 p = alloc(2) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x"
23 // Escape analysis used to miss inlined code in closures.
25 func() { // ERROR "func literal does not escape"
26 p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x"
27 }()
29 f = func() { // ERROR "func literal escapes to heap"
30 p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x"
32 f()
35 func f2() {} // ERROR "can inline f2"
37 // No inline for panic, recover.
38 func f3() { panic(1) }
39 func f4() { recover() }
41 func f5() *byte {
42 type T struct {
43 x [1]byte
45 t := new(T) // ERROR "new.T. escapes to heap"
46 return &t.x[0] // ERROR "&t.x.0. escapes to heap"
49 func f6() *byte {
50 type T struct {
51 x struct {
52 y byte
55 t := new(T) // ERROR "new.T. escapes to heap"
56 return &t.x.y // ERROR "&t.x.y escapes to heap"