]> Cypherpunks repositories - gostls13.git/commitdiff
test: add missing escape analysis test
authorTobias Klauser <tklauser@distanz.ch>
Thu, 10 Aug 2017 10:58:10 +0000 (12:58 +0200)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 11 Aug 2017 00:56:21 +0000 (00:56 +0000)
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 <t@avelino.xxx>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>

test/escape2.go
test/escape2n.go

index e10dbc2accbd36a95335651e500c4abf8a390c10..ef3d6a88bf3822977a2a191b8b2a9b0e71be611f 100644 (file)
@@ -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
index 74f6f8dd65efacf93cc16c5842cd9b23456c4582..b1130d3c3c9d3d2fa2e0f2bcbbe55cf270807ca9 100644 (file)
@@ -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
+       }
+}