3 // Copyright 2015 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 escape analysis when assigning to indirections.
13 type ConstPtr struct {
19 type ConstPtr2 struct {
25 i := 0 // ERROR "moved to heap: i"
26 x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
27 // BAD: i should not escape here
32 func constptr01() *ConstPtr {
33 i := 0 // ERROR "moved to heap: i"
34 x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap"
39 func constptr02() ConstPtr {
40 i := 0 // ERROR "moved to heap: i"
41 x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
46 func constptr03() **ConstPtr {
47 i := 0 // ERROR "moved to heap: i"
48 x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap" "moved to heap: x"
54 i := 0 // ERROR "moved to heap: i"
55 x := &ConstPtr{} // ERROR "&ConstPtr{} escapes to heap"
61 i := 0 // ERROR "moved to heap: i"
62 x := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
64 sink = *x // ERROR "\*x escapes to heap"
67 func constptr4() *ConstPtr {
68 p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
69 *p = *&ConstPtr{} // ERROR "&ConstPtr{} does not escape"
73 func constptr5() *ConstPtr {
74 p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
75 p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
80 // BAD: p should not escape here
81 func constptr6(p *ConstPtr) { // ERROR "leaking param content: p"
82 p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
87 func constptr7() **ConstPtr {
88 p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap" "moved to heap: p"
95 func constptr8() *ConstPtr {
96 p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
102 func constptr9() ConstPtr {
103 p := new(ConstPtr) // ERROR "new\(ConstPtr\) does not escape"
105 i := 0 // ERROR "moved to heap: i"
111 func constptr10() ConstPtr {
112 x := &ConstPtr{} // ERROR "moved to heap: x" "&ConstPtr{} escapes to heap"
113 i := 0 // ERROR "moved to heap: i"
115 p = &ConstPtr{p: &i, x: &x} // ERROR "&ConstPtr{...} does not escape"
121 func constptr11() *ConstPtr {
122 i := 0 // ERROR "moved to heap: i"
123 p := new(ConstPtr) // ERROR "new\(ConstPtr\) escapes to heap"
124 p1 := &ConstPtr{} // ERROR "&ConstPtr{} does not escape"
130 func foo(p **int) { // ERROR "p does not escape"
131 i := 0 // ERROR "moved to heap: i"
136 func foo1(p *int) { // ERROR "p does not escape"
137 i := 0 // ERROR "moved to heap: i"
146 x := new(int) // ERROR "moved to heap: x" "new\(int\) escapes to heap"
151 i := 0 // ERROR "moved to heap: i"
158 var x byte // ERROR "moved to heap: x"