blob: 222ef8bc22a064cc8c2e507034028cd82e26a174 [file] [log] [blame]
Patrice Arruda748609c2020-06-25 12:12:21 -07001// errorcheck -0 -m -l
Dan Willemsen09eb3b12015-09-16 14:34:17 -07002
Dan Willemsen38f2dba2016-07-08 14:54:35 -07003// Copyright 2015 The Go Authors. All rights reserved.
Dan Willemsen09eb3b12015-09-16 14:34:17 -07004// 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 function parameters.
8
9package foo
10
11var Ssink *string
12
13type U struct {
14 _sp *string
15 _spp **string
16}
17
18func A(sp *string, spp **string) U { // ERROR "leaking param: sp to result ~r2 level=0$" "leaking param: spp to result ~r2 level=0$"
19 return U{sp, spp}
20}
21
Colin Cross430342c2019-09-07 08:36:04 -070022func B(spp **string) U { // ERROR "leaking param: spp to result ~r1 level=0$"
Dan Willemsen09eb3b12015-09-16 14:34:17 -070023 return U{*spp, spp}
24}
25
26func tA1() {
27 s := "cat"
Colin Cross430342c2019-09-07 08:36:04 -070028 sp := &s
29 spp := &sp
Dan Willemsen09eb3b12015-09-16 14:34:17 -070030 u := A(sp, spp)
31 _ = u
32 println(s)
33}
34
35func tA2() {
36 s := "cat"
Colin Cross430342c2019-09-07 08:36:04 -070037 sp := &s
38 spp := &sp
Dan Willemsen09eb3b12015-09-16 14:34:17 -070039 u := A(sp, spp)
40 println(*u._sp)
41}
42
43func tA3() {
44 s := "cat"
Colin Cross430342c2019-09-07 08:36:04 -070045 sp := &s
46 spp := &sp
Dan Willemsen09eb3b12015-09-16 14:34:17 -070047 u := A(sp, spp)
48 println(**u._spp)
49}
50
51func tB1() {
52 s := "cat"
Colin Cross430342c2019-09-07 08:36:04 -070053 sp := &s
54 spp := &sp
Dan Willemsen09eb3b12015-09-16 14:34:17 -070055 u := B(spp)
56 _ = u
57 println(s)
58}
59
60func tB2() {
61 s := "cat"
Colin Cross430342c2019-09-07 08:36:04 -070062 sp := &s
63 spp := &sp
Dan Willemsen09eb3b12015-09-16 14:34:17 -070064 u := B(spp)
65 println(*u._sp)
66}
67
68func tB3() {
69 s := "cat"
Colin Cross430342c2019-09-07 08:36:04 -070070 sp := &s
71 spp := &sp
Dan Willemsen09eb3b12015-09-16 14:34:17 -070072 u := B(spp)
73 println(**u._spp)
74}