From: Tobias Klauser Date: Thu, 10 Aug 2017 10:58:10 +0000 (+0200) Subject: test: add missing escape analysis test X-Git-Tag: go1.10beta1~1662 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d7ec89c19846d8c1d89d510cd7634ae9de640ac0;p=gostls13.git test: add missing escape analysis test https://golang.org/cl/37508 added an escape analysis test for #12397 to escape2.go but missed to add it to escape2n.go. The comment at the top of the former states that the latter should contain all the same tests and the tests only differ in using -N to compile. Conform to this by adding the function issue12397 to escape2n.go as well. Also fix a whitespace difference in escape2.go, so the two files match exactly (except for the comment at the top). Change-Id: I3a09cf95169bf2150a25d6b4ec9e147265d36760 Reviewed-on: https://go-review.googlesource.com/54610 Reviewed-by: Avelino Reviewed-by: Josh Bleecher Snyder Run-TryBot: Josh Bleecher Snyder --- diff --git a/test/escape2.go b/test/escape2.go index e10dbc2acc..ef3d6a88bf 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -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 "&i escapes to heap$" "leaking closure reference i" + px = &i // ERROR "&i escapes to heap$" "leaking closure reference i" }() } _ = px diff --git a/test/escape2n.go b/test/escape2n.go index 74f6f8dd65..b1130d3c3c 100644 --- a/test/escape2n.go +++ b/test/escape2n.go @@ -1824,3 +1824,18 @@ func issue11387(x int) func() int { copy(slice2, slice1) return slice2[0] } + +func issue12397(x, y int) { // ERROR "moved to heap: y$" + // x does not escape below, because all relevant code is dead. + if false { + gxx = &x + } else { + gxx = &y // ERROR "&y escapes to heap$" + } + + if true { + gxx = &y // ERROR "&y escapes to heap$" + } else { + gxx = &x + } +}