Skip to content

Commit

Permalink
cmd/compile: trim more unnecessary escape analysis messages
Browse files Browse the repository at this point in the history
"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 <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
mdempsky committed Apr 2, 2019
1 parent e29f74e commit 131eb8f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 36 deletions.
8 changes: 0 additions & 8 deletions src/cmd/compile/internal/gc/esc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
level.int() > 0 {
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
Expand Down Expand Up @@ -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
// original variable.
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))
}

Expand Down
24 changes: 12 additions & 12 deletions test/escape2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,15 @@ func foo124(x **int) { // ERROR "foo124 x does not escape$"
var i int // ERROR "moved to heap: i$"
p := &i
func() { // ERROR "foo124 func literal does not escape$"
*x = p // ERROR "leaking closure reference p$"
*x = p
}()
}

func foo125(ch chan *int) { // ERROR "foo125 ch does not escape$"
var i int // ERROR "moved to heap: i$"
p := &i
func() { // ERROR "foo125 func literal does not escape$"
ch <- p // ERROR "leaking closure reference p$"
ch <- p
}()
}

Expand All @@ -1204,7 +1204,7 @@ func foo126() {
// loopdepth 1
var i int // ERROR "moved to heap: i$"
func() { // ERROR "foo126 func literal does not escape$"
px = &i // ERROR "leaking closure reference i"
px = &i
}()
}
_ = px
Expand All @@ -1230,9 +1230,9 @@ func foo129() {
var i int // ERROR "moved to heap: i$"
p := &i
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$"
r := q // ERROR "leaking closure reference q$"
r := q
px = r
}()
}()
Expand All @@ -1242,29 +1242,29 @@ func foo130() {
for {
var i int // ERROR "moved to heap: i$"
func() { // ERROR "foo130 func literal does not escape$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}
}

func foo131() {
var i int // ERROR "moved to heap: i$"
func() { // ERROR "foo131 func literal does not escape$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}

func foo132() {
var i int // ERROR "moved to heap: i$"
go func() { // ERROR "func literal escapes to heap$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}

func foo133() {
var i int // ERROR "moved to heap: i$"
defer func() { // ERROR "foo133 func literal does not escape$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}

Expand Down Expand Up @@ -1296,9 +1296,9 @@ func foo136() {
var i int // ERROR "moved to heap: i$"
p := &i
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$"
r := q // ERROR "leaking closure reference q$"
r := q
px = r
}()
}()
Expand All @@ -1308,7 +1308,7 @@ func foo137() {
var i int // ERROR "moved to heap: i$"
p := &i
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$"
r := q
_ = r
Expand Down
24 changes: 12 additions & 12 deletions test/escape2n.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,15 @@ func foo124(x **int) { // ERROR "foo124 x does not escape$"
var i int // ERROR "moved to heap: i$"
p := &i
func() { // ERROR "foo124 func literal does not escape$"
*x = p // ERROR "leaking closure reference p$"
*x = p
}()
}

func foo125(ch chan *int) { // ERROR "foo125 ch does not escape$"
var i int // ERROR "moved to heap: i$"
p := &i
func() { // ERROR "foo125 func literal does not escape$"
ch <- p // ERROR "leaking closure reference p$"
ch <- p
}()
}

Expand All @@ -1204,7 +1204,7 @@ func foo126() {
// loopdepth 1
var i int // ERROR "moved to heap: i$"
func() { // ERROR "foo126 func literal does not escape$"
px = &i // ERROR "leaking closure reference i"
px = &i
}()
}
_ = px
Expand All @@ -1230,9 +1230,9 @@ func foo129() {
var i int // ERROR "moved to heap: i$"
p := &i
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$"
r := q // ERROR "leaking closure reference q$"
r := q
px = r
}()
}()
Expand All @@ -1242,29 +1242,29 @@ func foo130() {
for {
var i int // ERROR "moved to heap: i$"
func() { // ERROR "foo130 func literal does not escape$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}
}

func foo131() {
var i int // ERROR "moved to heap: i$"
func() { // ERROR "foo131 func literal does not escape$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}

func foo132() {
var i int // ERROR "moved to heap: i$"
go func() { // ERROR "func literal escapes to heap$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}

func foo133() {
var i int // ERROR "moved to heap: i$"
defer func() { // ERROR "foo133 func literal does not escape$"
px = &i // ERROR "leaking closure reference i$"
px = &i
}()
}

Expand Down Expand Up @@ -1296,9 +1296,9 @@ func foo136() {
var i int // ERROR "moved to heap: i$"
p := &i
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$"
r := q // ERROR "leaking closure reference q$"
r := q
px = r
}()
}()
Expand All @@ -1308,7 +1308,7 @@ func foo137() {
var i int // ERROR "moved to heap: i$"
p := &i
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$"
r := q
_ = r
Expand Down
8 changes: 4 additions & 4 deletions test/escape_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ func bff(a, b *string) U { // ERROR "leaking param: a to result ~r2 level=0$" "l

func tbff1() *string {
a := "cat"
b := "dog" // ERROR "moved to heap: b$"
b := "dog" // ERROR "moved to heap: b$"
u := bff(&a, &b)
_ = u[0]
return &b
}

// BAD: need fine-grained analysis to track u[0] and u[1] differently.
func tbff2() *string {
a := "cat" // ERROR "moved to heap: a$"
b := "dog" // ERROR "moved to heap: b$"
a := "cat" // ERROR "moved to heap: a$"
b := "dog" // ERROR "moved to heap: b$"
u := bff(&a, &b)
_ = u[0]
return u[1]
Expand Down Expand Up @@ -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;
// large array literals are heap allocated;
// 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
// 4 x 4,000,000 exceeds MaxStackVarSize, therefore it must be heap allocated if pointers are 4 bytes or larger.
Expand Down

0 comments on commit 131eb8f

Please sign in to comment.