2019-07-25 13:54:03 -06:00
|
|
|
// errorcheck -0 -m -l
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
|
2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test, using compiler diagnostic flags, that the escape analysis is working.
|
|
|
|
// Compiles but does not run. Inlining is disabled.
|
|
|
|
|
|
|
|
package foo
|
|
|
|
|
2019-04-16 14:48:19 -06:00
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2017-03-24 10:00:17 -06:00
|
|
|
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
func noleak(p *int) int { // ERROR "p does not escape"
|
|
|
|
return *p
|
|
|
|
}
|
|
|
|
|
|
|
|
func leaktoret(p *int) *int { // ERROR "leaking param: p to result"
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:54:31 -06:00
|
|
|
func leaktoret2(p *int) (*int, *int) { // ERROR "leaking param: p to result ~r0" "leaking param: p to result ~r1"
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
return p, p
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:54:31 -06:00
|
|
|
func leaktoret22(p, q *int) (*int, *int) { // ERROR "leaking param: p to result ~r0" "leaking param: q to result ~r1"
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
return p, q
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:54:31 -06:00
|
|
|
func leaktoret22b(p, q *int) (*int, *int) { // ERROR "leaking param: p to result ~r1" "leaking param: q to result ~r0"
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
return leaktoret22(q, p)
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:54:31 -06:00
|
|
|
func leaktoret22c(p, q *int) (*int, *int) { // ERROR "leaking param: p to result ~r1" "leaking param: q to result ~r0"
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
r, s := leaktoret22(q, p)
|
|
|
|
return r, s
|
|
|
|
}
|
|
|
|
|
|
|
|
func leaktoret22d(p, q *int) (r, s *int) { // ERROR "leaking param: p to result s" "leaking param: q to result r"
|
|
|
|
r, s = leaktoret22(q, p)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func leaktoret22e(p, q *int) (r, s *int) { // ERROR "leaking param: p to result s" "leaking param: q to result r"
|
|
|
|
r, s = leaktoret22(q, p)
|
|
|
|
return r, s
|
|
|
|
}
|
|
|
|
|
|
|
|
func leaktoret22f(p, q *int) (r, s *int) { // ERROR "leaking param: p to result s" "leaking param: q to result r"
|
|
|
|
rr, ss := leaktoret22(q, p)
|
|
|
|
return rr, ss
|
|
|
|
}
|
|
|
|
|
|
|
|
var gp *int
|
|
|
|
|
|
|
|
func leaktosink(p *int) *int { // ERROR "leaking param: p"
|
|
|
|
gp = p
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func f1() {
|
|
|
|
var x int
|
2019-04-01 12:58:33 -06:00
|
|
|
p := noleak(&x)
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
_ = p
|
|
|
|
}
|
|
|
|
|
|
|
|
func f2() {
|
|
|
|
var x int
|
2019-04-01 12:58:33 -06:00
|
|
|
p := leaktoret(&x)
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
_ = p
|
|
|
|
}
|
|
|
|
|
|
|
|
func f3() {
|
2019-04-16 14:48:19 -06:00
|
|
|
var x int // ERROR "moved to heap: x"
|
2019-04-01 12:58:33 -06:00
|
|
|
p := leaktoret(&x)
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
gp = p
|
|
|
|
}
|
|
|
|
|
|
|
|
func f4() {
|
2019-04-16 14:48:19 -06:00
|
|
|
var x int // ERROR "moved to heap: x"
|
2019-04-01 12:58:33 -06:00
|
|
|
p, q := leaktoret2(&x)
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
gp = p
|
|
|
|
gp = q
|
|
|
|
}
|
|
|
|
|
|
|
|
func f5() {
|
|
|
|
var x int
|
2019-04-01 12:58:33 -06:00
|
|
|
leaktoret22(leaktoret2(&x))
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func f6() {
|
2019-04-16 14:48:19 -06:00
|
|
|
var x int // ERROR "moved to heap: x"
|
2019-04-01 12:58:33 -06:00
|
|
|
px1, px2 := leaktoret22(leaktoret2(&x))
|
cmd/gc: escape analysis to track flow of in to out parameters.
includes step 0: synthesize outparams, from 6600044
includes step 1,2: give outparams loopdepth 0 and verify unchanged results
generate esc:$mask tags, but still tie to sink if a param has mask != 0
from 6610054
adds final steps:
- have esccall generate n->escretval, a list of nodes the function results flow to
- use these in esccall and ORETURN/OAS2FUNC/and f(g())
- only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval
R=rsc, bradfitz
CC=dave, gobot, golang-dev, iant, rsc
https://golang.org/cl/6741044
2012-10-29 06:38:21 -06:00
|
|
|
gp = px1
|
|
|
|
_ = px2
|
|
|
|
}
|
|
|
|
|
|
|
|
type T struct{ x int }
|
|
|
|
|
|
|
|
func (t *T) Foo(u int) (*T, bool) { // ERROR "leaking param: t to result"
|
|
|
|
t.x += u
|
|
|
|
return t, true
|
|
|
|
}
|
|
|
|
|
|
|
|
func f7() *T {
|
|
|
|
r, _ := new(T).Foo(42) // ERROR "new.T. escapes to heap"
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func leakrecursive1(p, q *int) (*int, *int) { // ERROR "leaking param: p" "leaking param: q"
|
|
|
|
return leakrecursive2(q, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func leakrecursive2(p, q *int) (*int, *int) { // ERROR "leaking param: p" "leaking param: q"
|
|
|
|
if *p > *q {
|
|
|
|
return leakrecursive1(q, p)
|
|
|
|
}
|
|
|
|
// without this, leakrecursive? are safe for p and q, b/c in fact their graph does not have leaking edges.
|
|
|
|
return p, q
|
|
|
|
}
|
|
|
|
|
2012-11-07 13:15:21 -07:00
|
|
|
var global interface{}
|
|
|
|
|
|
|
|
type T1 struct {
|
|
|
|
X *int
|
|
|
|
}
|
|
|
|
|
|
|
|
type T2 struct {
|
|
|
|
Y *T1
|
|
|
|
}
|
|
|
|
|
cmd/compile: update escape analysis tests for newescape
The new escape analysis implementation tries to emit debugging
diagnostics that are compatible with the existing implementation, but
there's a handful of cases that are easier to handle by updating the
test expectations instead.
For regress tests that need updating, the original file is copied to
oldescapeXXX.go.go with -newescape=false added to the //errorcheck
line, while the file is updated in place with -newescape=true and new
test requirements.
Notable test changes:
1) escape_because.go looks for a lot of detailed internal debugging
messages that are fairly particular to how esc.go works and that I
haven't attempted to port over to escape.go yet.
2) There are a lot of "leaking param: x to result ~r1 level=-1"
messages for code like
func(p *int) *T { return &T{p} }
that were simply wrong. Here &T must be heap allocated unconditionally
(because it's being returned); and since p is stored into it, p
escapes unconditionally too. esc.go incorrectly reports that p escapes
conditionally only if the returned pointer escaped.
3) esc.go used to print each "leaking param" analysis result as it
discovered them, which could lead to redundant messages (e.g., that a
param leaks at level=0 and level=1). escape.go instead prints
everything at the end, once it knows the shortest path to each sink.
4) esc.go didn't precisely model direct-interface types, resulting in
some values unnecessarily escaping to the heap when stored into
non-escaping interface values.
5) For functions written in assembly, esc.go only printed "does not
escape" messages, whereas escape.go prints "does not escape" or
"leaking param" as appropriate, consistent with the behavior for
functions written in Go.
6) 12 tests included "BAD" annotations identifying cases where esc.go
was unnecessarily heap allocating something. These are all fixed by
escape.go.
Updates #23109.
Change-Id: Iabc9eb14c94c9cadde3b183478d1fd54f013502f
Reviewed-on: https://go-review.googlesource.com/c/go/+/170447
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2019-04-02 15:44:13 -06:00
|
|
|
func f8(p *T1) (k T2) { // ERROR "leaking param: p$"
|
2012-11-07 13:15:21 -07:00
|
|
|
if p == nil {
|
|
|
|
k = T2{}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:27:32 -07:00
|
|
|
// should make p leak always
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
global = p
|
2012-11-07 13:15:21 -07:00
|
|
|
return T2{p}
|
|
|
|
}
|
|
|
|
|
|
|
|
func f9() {
|
|
|
|
var j T1 // ERROR "moved to heap: j"
|
2019-04-01 12:58:33 -06:00
|
|
|
f8(&j)
|
2012-11-07 13:15:21 -07:00
|
|
|
}
|
2013-08-08 11:46:30 -06:00
|
|
|
|
|
|
|
func f10() {
|
|
|
|
// These don't escape but are too big for the stack
|
2015-05-20 13:16:34 -06:00
|
|
|
var x [1 << 30]byte // ERROR "moved to heap: x"
|
|
|
|
var y = make([]byte, 1<<30) // ERROR "make\(\[\]byte, 1 << 30\) escapes to heap"
|
2013-08-08 11:46:30 -06:00
|
|
|
_ = x[0] + y[0]
|
|
|
|
}
|
2017-03-24 10:00:17 -06:00
|
|
|
|
|
|
|
// Test for issue 19687 (passing to unnamed parameters does not escape).
|
|
|
|
func f11(**int) {
|
|
|
|
}
|
|
|
|
func f12(_ **int) {
|
|
|
|
}
|
|
|
|
func f13() {
|
|
|
|
var x *int
|
2019-04-01 12:58:33 -06:00
|
|
|
f11(&x)
|
|
|
|
f12(&x)
|
cmd/compile: silence esc diagnostics about directiface OCONVIFACEs
In general, a conversion to interface type may require values to be
boxed, which in turn necessitates escape analysis to determine whether
the boxed representation can be stack allocated.
However, esc.go used to unconditionally print escape analysis
decisions about OCONVIFACE, even for conversions that don't require
boxing (e.g., pointers, channels, maps, functions).
For test compatibility with esc.go, escape.go similarly printed these
useless diagnostics. This CL removes the diagnostics, and updates test
expectations accordingly.
Change-Id: I97c57a4a08e44d265bba516c78426ff4f2bf1e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/192697
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-08-30 11:56:30 -06:00
|
|
|
runtime.KeepAlive(&x)
|
2017-03-24 10:00:17 -06:00
|
|
|
}
|
2018-03-07 16:10:27 -07:00
|
|
|
|
|
|
|
// Test for issue 24305 (passing to unnamed receivers does not escape).
|
|
|
|
type U int
|
|
|
|
|
|
|
|
func (*U) M() {}
|
|
|
|
func (_ *U) N() {}
|
|
|
|
|
|
|
|
func _() {
|
|
|
|
var u U
|
2019-04-01 12:58:33 -06:00
|
|
|
u.M()
|
|
|
|
u.N()
|
2018-03-07 16:10:27 -07:00
|
|
|
}
|
2018-04-06 14:21:26 -06:00
|
|
|
|
2020-08-12 10:12:57 -06:00
|
|
|
func fbad24305() {
|
2021-06-23 01:31:16 -06:00
|
|
|
var u U
|
2020-08-12 10:12:57 -06:00
|
|
|
(*U).M(&u)
|
|
|
|
(*U).N(&u)
|
|
|
|
}
|
|
|
|
|
2018-04-06 14:21:26 -06:00
|
|
|
// Issue 24730: taking address in a loop causes unnecessary escape
|
|
|
|
type T24730 struct {
|
|
|
|
x [64]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *T24730) g() { // ERROR "t does not escape"
|
2019-04-01 12:58:33 -06:00
|
|
|
y := t.x[:]
|
|
|
|
for i := range t.x[:] {
|
|
|
|
y = t.x[:]
|
2018-04-06 14:21:26 -06:00
|
|
|
y[i] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var z *byte
|
2019-04-01 12:58:33 -06:00
|
|
|
for i := range t.x[:] {
|
|
|
|
z = &t.x[i]
|
2018-04-06 14:21:26 -06:00
|
|
|
*z = 2
|
|
|
|
}
|
|
|
|
}
|
2018-04-17 14:28:13 -06:00
|
|
|
|
|
|
|
// Issue 15730: copy causes unnecessary escape
|
|
|
|
|
|
|
|
var sink []byte
|
|
|
|
var sink2 []int
|
|
|
|
var sink3 []*int
|
|
|
|
|
|
|
|
func f15730a(args ...interface{}) { // ERROR "args does not escape"
|
|
|
|
for _, arg := range args {
|
|
|
|
switch a := arg.(type) {
|
|
|
|
case string:
|
|
|
|
copy(sink, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func f15730b(args ...interface{}) { // ERROR "args does not escape"
|
|
|
|
for _, arg := range args {
|
|
|
|
switch a := arg.(type) {
|
|
|
|
case []int:
|
|
|
|
copy(sink2, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func f15730c(args ...interface{}) { // ERROR "leaking param content: args"
|
|
|
|
for _, arg := range args {
|
|
|
|
switch a := arg.(type) {
|
|
|
|
case []*int:
|
|
|
|
// copy pointerful data should cause escape
|
|
|
|
copy(sink3, a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 13:54:14 -07:00
|
|
|
|
|
|
|
// Issue 29000: unnamed parameter is not handled correctly
|
|
|
|
|
|
|
|
var sink4 interface{}
|
|
|
|
var alwaysFalse = false
|
|
|
|
|
|
|
|
func f29000(_ int, x interface{}) { // ERROR "leaking param: x"
|
|
|
|
sink4 = x
|
|
|
|
if alwaysFalse {
|
|
|
|
g29000()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func g29000() {
|
|
|
|
x := 1
|
|
|
|
f29000(2, x) // ERROR "x escapes to heap"
|
|
|
|
}
|
2019-04-16 14:48:19 -06:00
|
|
|
|
|
|
|
// Issue 28369: taking an address of a parameter and converting it into a uintptr causes an
|
|
|
|
// unnecessary escape.
|
|
|
|
|
|
|
|
var sink28369 uintptr
|
|
|
|
|
|
|
|
func f28369(n int) int {
|
|
|
|
if n == 0 {
|
|
|
|
sink28369 = uintptr(unsafe.Pointer(&n))
|
|
|
|
return n
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1 + f28369(n-1)
|
|
|
|
}
|
2021-02-27 10:41:19 -07:00
|
|
|
|
|
|
|
// Issue 44614: parameters that flow to a heap-allocated result
|
|
|
|
// parameter must be recorded as a heap-flow rather than a
|
|
|
|
// result-flow.
|
|
|
|
|
|
|
|
// N.B., must match "leaking param: p",
|
|
|
|
// but *not* "leaking param: p to result r level=0".
|
|
|
|
func f(p *int) (r *int) { // ERROR "leaking param: p$" "moved to heap: r"
|
|
|
|
sink4 = &r
|
|
|
|
return p
|
|
|
|
}
|