mirror of
https://github.com/golang/go
synced 2024-11-22 21:10:03 -07:00
cmd/compile: trim more unnecessary escape analysis messages
"leaking closure reference" is redundant for similar reasons as "&x escapes to heap" for OADDR nodes: the reference itself does not allocate, and we already report when the referenced variable is moved to heap. "mark escaped content" is redundant with "leaking param content". Updates #23109. Change-Id: I1ab599cb1e8434f1918dd80596a70cba7dc8a0cf Reviewed-on: https://go-review.googlesource.com/c/go/+/170321 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
e29f74efb9
commit
131eb8fbf8
@ -1837,10 +1837,6 @@ func (e *EscState) escwalkBody(level Level, dst *Node, src *Node, step *EscStep,
|
|||||||
src.Op == ONAME && src.Class() == PPARAM && src.Esc&EscMask < EscHeap &&
|
src.Op == ONAME && src.Class() == PPARAM && src.Esc&EscMask < EscHeap &&
|
||||||
level.int() > 0 {
|
level.int() > 0 {
|
||||||
src.Esc = escMax(EscContentEscapes|src.Esc, EscNone)
|
src.Esc = escMax(EscContentEscapes|src.Esc, EscNone)
|
||||||
if Debug['m'] != 0 {
|
|
||||||
Warnl(src.Pos, "mark escaped content: %S", src)
|
|
||||||
step.describe(src)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leaks = level.int() <= 0 && level.guaranteedDereference() <= 0 && dstE.Loopdepth < modSrcLoopdepth
|
leaks = level.int() <= 0 && level.guaranteedDereference() <= 0 && dstE.Loopdepth < modSrcLoopdepth
|
||||||
@ -1880,10 +1876,6 @@ func (e *EscState) escwalkBody(level Level, dst *Node, src *Node, step *EscStep,
|
|||||||
// Treat a captured closure variable as equivalent to the
|
// Treat a captured closure variable as equivalent to the
|
||||||
// original variable.
|
// original variable.
|
||||||
if src.IsClosureVar() {
|
if src.IsClosureVar() {
|
||||||
if leaks && Debug['m'] != 0 {
|
|
||||||
Warnl(src.Pos, "leaking closure reference %S", src)
|
|
||||||
step.describe(src)
|
|
||||||
}
|
|
||||||
e.escwalk(level, dst, src.Name.Defn, e.stepWalk(dst, src.Name.Defn, "closure-var", step))
|
e.escwalk(level, dst, src.Name.Defn, e.stepWalk(dst, src.Name.Defn, "closure-var", step))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1186,7 +1186,7 @@ func foo124(x **int) { // ERROR "foo124 x does not escape$"
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo124 func literal does not escape$"
|
func() { // ERROR "foo124 func literal does not escape$"
|
||||||
*x = p // ERROR "leaking closure reference p$"
|
*x = p
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1194,7 +1194,7 @@ func foo125(ch chan *int) { // ERROR "foo125 ch does not escape$"
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo125 func literal does not escape$"
|
func() { // ERROR "foo125 func literal does not escape$"
|
||||||
ch <- p // ERROR "leaking closure reference p$"
|
ch <- p
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1204,7 +1204,7 @@ func foo126() {
|
|||||||
// loopdepth 1
|
// loopdepth 1
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
func() { // ERROR "foo126 func literal does not escape$"
|
func() { // ERROR "foo126 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
_ = px
|
_ = px
|
||||||
@ -1230,9 +1230,9 @@ func foo129() {
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo129 func literal does not escape$"
|
func() { // ERROR "foo129 func literal does not escape$"
|
||||||
q := p // ERROR "leaking closure reference p$"
|
q := p
|
||||||
func() { // ERROR "foo129.func1 func literal does not escape$"
|
func() { // ERROR "foo129.func1 func literal does not escape$"
|
||||||
r := q // ERROR "leaking closure reference q$"
|
r := q
|
||||||
px = r
|
px = r
|
||||||
}()
|
}()
|
||||||
}()
|
}()
|
||||||
@ -1242,7 +1242,7 @@ func foo130() {
|
|||||||
for {
|
for {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
func() { // ERROR "foo130 func literal does not escape$"
|
func() { // ERROR "foo130 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1250,21 +1250,21 @@ func foo130() {
|
|||||||
func foo131() {
|
func foo131() {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
func() { // ERROR "foo131 func literal does not escape$"
|
func() { // ERROR "foo131 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func foo132() {
|
func foo132() {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
go func() { // ERROR "func literal escapes to heap$"
|
go func() { // ERROR "func literal escapes to heap$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func foo133() {
|
func foo133() {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
defer func() { // ERROR "foo133 func literal does not escape$"
|
defer func() { // ERROR "foo133 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,9 +1296,9 @@ func foo136() {
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
go func() { // ERROR "func literal escapes to heap$"
|
go func() { // ERROR "func literal escapes to heap$"
|
||||||
q := p // ERROR "leaking closure reference p$"
|
q := p
|
||||||
func() { // ERROR "foo136.func1 func literal does not escape$"
|
func() { // ERROR "foo136.func1 func literal does not escape$"
|
||||||
r := q // ERROR "leaking closure reference q$"
|
r := q
|
||||||
px = r
|
px = r
|
||||||
}()
|
}()
|
||||||
}()
|
}()
|
||||||
@ -1308,7 +1308,7 @@ func foo137() {
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo137 func literal does not escape$"
|
func() { // ERROR "foo137 func literal does not escape$"
|
||||||
q := p // ERROR "leaking closure reference p$"
|
q := p
|
||||||
go func() { // ERROR "func literal escapes to heap$"
|
go func() { // ERROR "func literal escapes to heap$"
|
||||||
r := q
|
r := q
|
||||||
_ = r
|
_ = r
|
||||||
|
@ -1186,7 +1186,7 @@ func foo124(x **int) { // ERROR "foo124 x does not escape$"
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo124 func literal does not escape$"
|
func() { // ERROR "foo124 func literal does not escape$"
|
||||||
*x = p // ERROR "leaking closure reference p$"
|
*x = p
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1194,7 +1194,7 @@ func foo125(ch chan *int) { // ERROR "foo125 ch does not escape$"
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo125 func literal does not escape$"
|
func() { // ERROR "foo125 func literal does not escape$"
|
||||||
ch <- p // ERROR "leaking closure reference p$"
|
ch <- p
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1204,7 +1204,7 @@ func foo126() {
|
|||||||
// loopdepth 1
|
// loopdepth 1
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
func() { // ERROR "foo126 func literal does not escape$"
|
func() { // ERROR "foo126 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
_ = px
|
_ = px
|
||||||
@ -1230,9 +1230,9 @@ func foo129() {
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo129 func literal does not escape$"
|
func() { // ERROR "foo129 func literal does not escape$"
|
||||||
q := p // ERROR "leaking closure reference p$"
|
q := p
|
||||||
func() { // ERROR "foo129.func1 func literal does not escape$"
|
func() { // ERROR "foo129.func1 func literal does not escape$"
|
||||||
r := q // ERROR "leaking closure reference q$"
|
r := q
|
||||||
px = r
|
px = r
|
||||||
}()
|
}()
|
||||||
}()
|
}()
|
||||||
@ -1242,7 +1242,7 @@ func foo130() {
|
|||||||
for {
|
for {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
func() { // ERROR "foo130 func literal does not escape$"
|
func() { // ERROR "foo130 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1250,21 +1250,21 @@ func foo130() {
|
|||||||
func foo131() {
|
func foo131() {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
func() { // ERROR "foo131 func literal does not escape$"
|
func() { // ERROR "foo131 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func foo132() {
|
func foo132() {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
go func() { // ERROR "func literal escapes to heap$"
|
go func() { // ERROR "func literal escapes to heap$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func foo133() {
|
func foo133() {
|
||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
defer func() { // ERROR "foo133 func literal does not escape$"
|
defer func() { // ERROR "foo133 func literal does not escape$"
|
||||||
px = &i // ERROR "leaking closure reference i$"
|
px = &i
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,9 +1296,9 @@ func foo136() {
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
go func() { // ERROR "func literal escapes to heap$"
|
go func() { // ERROR "func literal escapes to heap$"
|
||||||
q := p // ERROR "leaking closure reference p$"
|
q := p
|
||||||
func() { // ERROR "foo136.func1 func literal does not escape$"
|
func() { // ERROR "foo136.func1 func literal does not escape$"
|
||||||
r := q // ERROR "leaking closure reference q$"
|
r := q
|
||||||
px = r
|
px = r
|
||||||
}()
|
}()
|
||||||
}()
|
}()
|
||||||
@ -1308,7 +1308,7 @@ func foo137() {
|
|||||||
var i int // ERROR "moved to heap: i$"
|
var i int // ERROR "moved to heap: i$"
|
||||||
p := &i
|
p := &i
|
||||||
func() { // ERROR "foo137 func literal does not escape$"
|
func() { // ERROR "foo137 func literal does not escape$"
|
||||||
q := p // ERROR "leaking closure reference p$"
|
q := p
|
||||||
go func() { // ERROR "func literal escapes to heap$"
|
go func() { // ERROR "func literal escapes to heap$"
|
||||||
r := q
|
r := q
|
||||||
_ = r
|
_ = r
|
||||||
|
@ -26,7 +26,7 @@ func bff(a, b *string) U { // ERROR "leaking param: a to result ~r2 level=0$" "l
|
|||||||
|
|
||||||
func tbff1() *string {
|
func tbff1() *string {
|
||||||
a := "cat"
|
a := "cat"
|
||||||
b := "dog" // ERROR "moved to heap: b$"
|
b := "dog" // ERROR "moved to heap: b$"
|
||||||
u := bff(&a, &b)
|
u := bff(&a, &b)
|
||||||
_ = u[0]
|
_ = u[0]
|
||||||
return &b
|
return &b
|
||||||
@ -34,8 +34,8 @@ func tbff1() *string {
|
|||||||
|
|
||||||
// BAD: need fine-grained analysis to track u[0] and u[1] differently.
|
// BAD: need fine-grained analysis to track u[0] and u[1] differently.
|
||||||
func tbff2() *string {
|
func tbff2() *string {
|
||||||
a := "cat" // ERROR "moved to heap: a$"
|
a := "cat" // ERROR "moved to heap: a$"
|
||||||
b := "dog" // ERROR "moved to heap: b$"
|
b := "dog" // ERROR "moved to heap: b$"
|
||||||
u := bff(&a, &b)
|
u := bff(&a, &b)
|
||||||
_ = u[0]
|
_ = u[0]
|
||||||
return u[1]
|
return u[1]
|
||||||
@ -71,7 +71,7 @@ func fuo(x *U, y *U) *string { // ERROR "leaking param: x to result ~r2 level=1$
|
|||||||
// pointers stored in small array literals do not escape;
|
// pointers stored in small array literals do not escape;
|
||||||
// large array literals are heap allocated;
|
// large array literals are heap allocated;
|
||||||
// pointers stored in large array literals escape.
|
// pointers stored in large array literals escape.
|
||||||
func hugeLeaks1(x **string, y **string) { // ERROR "leaking param content: x" "hugeLeaks1 y does not escape" "mark escaped content: x"
|
func hugeLeaks1(x **string, y **string) { // ERROR "leaking param content: x" "hugeLeaks1 y does not escape"
|
||||||
a := [10]*string{*y}
|
a := [10]*string{*y}
|
||||||
_ = a
|
_ = a
|
||||||
// 4 x 4,000,000 exceeds MaxStackVarSize, therefore it must be heap allocated if pointers are 4 bytes or larger.
|
// 4 x 4,000,000 exceeds MaxStackVarSize, therefore it must be heap allocated if pointers are 4 bytes or larger.
|
||||||
|
Loading…
Reference in New Issue
Block a user