aboutsummaryrefslogtreecommitdiff
path: root/test/escape4.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-02-23 23:09:53 -0500
committerRuss Cox <rsc@golang.org>2012-02-23 23:09:53 -0500
commit075eef4018b1c2ab37c9236e3265f0d2d816a04f (patch)
treee015195aecafd836d6e75f1aaeb0c36ddf852d8e /test/escape4.go
parentd45ee4cb5f44b2ebc79a65f1fcbc4d3f81fbdd40 (diff)
downloadgo-075eef4018b1c2ab37c9236e3265f0d2d816a04f.tar.gz
go-075eef4018b1c2ab37c9236e3265f0d2d816a04f.zip
gc: fix escape analysis + inlining + closure bug
R=ken2 CC=golang-dev, lvd https://golang.org/cl/5693056
Diffstat (limited to 'test/escape4.go')
-rw-r--r--test/escape4.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/escape4.go b/test/escape4.go
new file mode 100644
index 0000000000..ab3aee2244
--- /dev/null
+++ b/test/escape4.go
@@ -0,0 +1,33 @@
+// errchk -0 $G -m $D/$F.go
+
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test, using compiler diagnostic flags, that the escape analysis is working.
+// Compiles but does not run. Inlining is enabled.
+
+package foo
+
+var p *int
+
+func alloc(x int) *int { // ERROR "can inline alloc" "moved to heap: x"
+ return &x // ERROR "&x escapes to heap"
+}
+
+var f func()
+
+func f1() {
+ p = alloc(2) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x"
+
+ // Escape analysis used to miss inlined code in closures.
+
+ func() { // ERROR "func literal does not escape"
+ p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x"
+ }()
+
+ f = func() { // ERROR "func literal escapes to heap"
+ p = alloc(3) // ERROR "inlining call to alloc" "&x escapes to heap" "moved to heap: x"
+ }
+ f()
+}