]> Cypherpunks.ru repositories - gostls13.git/blob - test/escape_selfassign.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / escape_selfassign.go
1 // errorcheck -0 -m -l
2
3 // Copyright 2019 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 escape analysis for self assignments.
8
9 package escape
10
11 type S struct {
12         i  int
13         pi *int
14 }
15
16 var sink S
17
18 func f(p *S) { // ERROR "leaking param: p"
19         p.pi = &p.i
20         sink = *p
21 }
22
23 // BAD: "leaking param: p" is too conservative
24 func g(p *S) { // ERROR "leaking param: p"
25         p.pi = &p.i
26 }
27
28 func h() {
29         var s S // ERROR "moved to heap: s"
30         g(&s)
31         sink = s
32 }