diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2015-01-19 23:46:22 +0300 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2015-01-28 16:59:01 +0000 |
commit | 1b87f01239de499654b390a41a7f8e2b453789dc (patch) | |
tree | e346c4ea2d5fe828abcbf55121ec149f3b99b623 /test/escape2.go | |
parent | 2059ffbc8db0dff3fd9780a817f76e95559193ba (diff) | |
download | go-git-1b87f01239de499654b390a41a7f8e2b453789dc.tar.gz |
cmd/gc: improve escape analysis for &T{...}
Currently all PTRLIT element initializers escape. There is no reason for that.
This change links STRUCTLIT to PTRLIT; STRUCTLIT element initializers are
already linked to the STRUCTLIT. As the result, PTRLIT element initializers
escape when PTRLIT itself escapes.
Change-Id: I89ecd8677cbf81addcfd469cd2fd461c0e9bf7dd
Reviewed-on: https://go-review.googlesource.com/3031
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'test/escape2.go')
-rw-r--r-- | test/escape2.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/escape2.go b/test/escape2.go index 6a46ce86ab..357ce4a8a8 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -1492,3 +1492,30 @@ func g() (x interface{}) { // ERROR "moved to heap: x" x = &x // ERROR "&x escapes to heap" return } + +var sink interface{} + +type Lit struct { + p *int +} + +func ptrlitNoescape() { + // Both literal and element do not escape. + i := 0 + x := &Lit{&i} // ERROR "&Lit literal does not escape" "&i does not escape" + _ = x +} + +func ptrlitNoEscape2() { + // Literal does not escape, but element does. + i := 0 // ERROR "moved to heap: i" + x := &Lit{&i} // ERROR "&Lit literal does not escape" "&i escapes to heap" + sink = *x +} + +func ptrlitEscape() { + // Both literal and element escape. + i := 0 // ERROR "moved to heap: i" + x := &Lit{&i} // ERROR "&Lit literal escapes to heap" "&i escapes to heap" + sink = x +} |