diff options
author | Matthew Dempsky <mdempsky@google.com> | 2019-04-02 14:44:13 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2019-04-16 16:20:39 +0000 |
commit | a9831633be548c039ada30a2fb9d7290c35ac0c0 (patch) | |
tree | 511937efe6dea2b8132e61eab191fde0f871379d /test/escape2.go | |
parent | 94e720059f902339699b8bf7b2b10897311b50f8 (diff) | |
download | go-a9831633be548c039ada30a2fb9d7290c35ac0c0.tar.gz go-a9831633be548c039ada30a2fb9d7290c35ac0c0.zip |
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>
Diffstat (limited to 'test/escape2.go')
-rw-r--r-- | test/escape2.go | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/test/escape2.go b/test/escape2.go index e3561a0f60..f682621c25 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -1,4 +1,4 @@ -// errorcheck -0 -m -l +// errorcheck -0 -m -l -newescape=true // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -121,7 +121,7 @@ func NewBar() *Bar { return &Bar{42, nil} // ERROR "&Bar literal escapes to heap$" } -func NewBarp(x *int) *Bar { // ERROR "leaking param: x to result ~r1 level=-1$" +func NewBarp(x *int) *Bar { // ERROR "leaking param: x$" return &Bar{42, x} // ERROR "&Bar literal escapes to heap$" } @@ -758,7 +758,7 @@ type LimitedFooer struct { N int64 } -func LimitFooer(r Fooer, n int64) Fooer { // ERROR "leaking param: r to result ~r2 level=-1$" +func LimitFooer(r Fooer, n int64) Fooer { // ERROR "leaking param: r$" return &LimitedFooer{r, n} // ERROR "&LimitedFooer literal escapes to heap$" } @@ -1360,7 +1360,7 @@ func F2([]byte) func F3(x []byte) // ERROR "F3 x does not escape$" -func F4(x []byte) +func F4(x []byte) // ERROR "leaking param: x$" func G() { var buf1 [10]byte @@ -1529,8 +1529,7 @@ type V struct { s *string } -// BAD -- level of leak ought to be 0 -func NewV(u U) *V { // ERROR "leaking param: u to result ~r1 level=-1" +func NewV(u U) *V { // ERROR "leaking param: u$" return &V{u.String()} // ERROR "&V literal escapes to heap$" } @@ -1543,7 +1542,7 @@ func foo152() { // issue 8176 - &x in type switch body not marked as escaping -func foo153(v interface{}) *int { // ERROR "leaking param: v to result ~r1 level=-1$" +func foo153(v interface{}) *int { // ERROR "foo153 v does not escape" switch x := v.(type) { case int: // ERROR "moved to heap: x$" return &x @@ -1806,7 +1805,7 @@ func issue10353() { issue10353a(x)() } -func issue10353a(x *int) func() { // ERROR "leaking param: x to result ~r1 level=-1$" +func issue10353a(x *int) func() { // ERROR "leaking param: x$" return func() { // ERROR "func literal escapes to heap$" println(*x) } |