aboutsummaryrefslogtreecommitdiff
path: root/test/escape5.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-11-07 15:15:21 -0500
committerRuss Cox <rsc@golang.org>2012-11-07 15:15:21 -0500
commit71282131a1ab0291834f41e606ebab6c5f0ca438 (patch)
treeb92db776f8fb2ae800caa2b9f1025c668739166d /test/escape5.go
parent1ebf2d85ba02ff7d3f97e52855166174d71666c2 (diff)
downloadgo-71282131a1ab0291834f41e606ebab6c5f0ca438.tar.gz
go-71282131a1ab0291834f41e606ebab6c5f0ca438.zip
cmd/gc: fix escape analysis bug
The code assumed that the only choices were EscNone, EscScope, and EscHeap, so that it makes sense to set EscScope only if the current setting is EscNone. Now that we have the many variants of EscReturn, this logic is false, and it was causing important EscScopes to be ignored in favor of EscReturn. Fixes #4360. R=ken2 CC=golang-dev, lvd https://golang.org/cl/6816103
Diffstat (limited to 'test/escape5.go')
-rw-r--r--test/escape5.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/escape5.go b/test/escape5.go
index 22c324f902..6b327fe9e3 100644
--- a/test/escape5.go
+++ b/test/escape5.go
@@ -117,3 +117,28 @@ func leakrecursive2(p, q *int) (*int, *int) { // ERROR "leaking param: p" "leaki
return p, q
}
+
+var global interface{}
+
+type T1 struct {
+ X *int
+}
+
+type T2 struct {
+ Y *T1
+}
+
+func f8(p *T1) (k T2) { // ERROR "leaking param: p to result k" "leaking param: p"
+ if p == nil {
+ k = T2{}
+ return
+ }
+
+ global = p // should make p leak always
+ return T2{p}
+}
+
+func f9() {
+ var j T1 // ERROR "moved to heap: j"
+ f8(&j) // ERROR "&j escapes to heap"
+}