Source file
test/escape_closure.go
1
2
3
4
5
6
7
8
9 package escape
10
11 var sink interface{}
12
13 func ClosureCallArgs0() {
14 x := 0
15 func(p *int) {
16 *p = 1
17 }(&x)
18 }
19
20 func ClosureCallArgs1() {
21 x := 0
22 for {
23 func(p *int) {
24 *p = 1
25 }(&x)
26 }
27 }
28
29 func ClosureCallArgs2() {
30 for {
31 x := 0
32 func(p *int) {
33 *p = 1
34 }(&x)
35 }
36 }
37
38 func ClosureCallArgs3() {
39 x := 0
40 func(p *int) {
41 sink = p
42 }(&x)
43 }
44
45 func ClosureCallArgs4() {
46 x := 0
47 _ = func(p *int) *int {
48 return p
49 }(&x)
50 }
51
52 func ClosureCallArgs5() {
53 x := 0
54
55
56 sink = func(p *int) *int {
57 return p
58 }(&x)
59 }
60
61 func ClosureCallArgs6() {
62 x := 0
63 func(p *int) {
64 sink = &p
65 }(&x)
66 }
67
68 func ClosureCallArgs7() {
69 var pp *int
70 for {
71 x := 0
72 func(p *int) {
73 pp = p
74 }(&x)
75 }
76 _ = pp
77 }
78
79 func ClosureCallArgs8() {
80 x := 0
81 defer func(p *int) {
82 *p = 1
83 }(&x)
84 }
85
86 func ClosureCallArgs9() {
87
88 x := 0
89 for {
90 defer func(p *int) {
91 *p = 1
92 }(&x)
93 }
94 }
95
96 func ClosureCallArgs10() {
97 for {
98 x := 0
99 defer func(p *int) {
100 *p = 1
101 }(&x)
102 }
103 }
104
105 func ClosureCallArgs11() {
106 x := 0
107 defer func(p *int) {
108 sink = p
109 }(&x)
110 }
111
112 func ClosureCallArgs12() {
113 x := 0
114 defer func(p *int) *int {
115 return p
116 }(&x)
117 }
118
119 func ClosureCallArgs13() {
120 x := 0
121 defer func(p *int) {
122 sink = &p
123 }(&x)
124 }
125
126 func ClosureCallArgs14() {
127 x := 0
128 p := &x
129 _ = func(p **int) *int {
130 return *p
131 }(&p)
132 }
133
134 func ClosureCallArgs15() {
135 x := 0
136 p := &x
137 sink = func(p **int) *int {
138 return *p
139 }(&p)
140 }
141
142 func ClosureLeak1(s string) string {
143 t := s + "YYYY"
144 return ClosureLeak1a(t)
145 }
146
147
148 func ClosureLeak1a(a ...string) string {
149 return func() string {
150 return a[0]
151 }()
152 }
153
154 func ClosureLeak2(s string) string {
155 t := s + "YYYY"
156 c := ClosureLeak2a(t)
157 return c
158 }
159 func ClosureLeak2a(a ...string) string {
160 return ClosureLeak2b(func() string {
161 return a[0]
162 })
163 }
164 func ClosureLeak2b(f func() string) string {
165 return f()
166 }
167
168 func ClosureIndirect() {
169 f := func(p *int) {}
170 f(new(int))
171
172 g := f
173 g(new(int))
174
175 h := nopFunc
176 h(new(int))
177 }
178
179 func nopFunc(p *int) {}
180
181 func ClosureIndirect2() {
182 f := func(p *int) *int { return p }
183
184 f(new(int))
185
186 g := f
187 g(new(int))
188
189 h := nopFunc2
190 h(new(int))
191 }
192
193 func nopFunc2(p *int) *int { return p }
194
View as plain text