aboutsummaryrefslogtreecommitdiff
path: root/test/escape2.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-02-05 07:00:38 -0500
committerRuss Cox <rsc@golang.org>2013-02-05 07:00:38 -0500
commitfd178d6a7e62796c71258ba155b957616be86ff4 (patch)
tree905b3bcdfa21372d9df68f19353b17e239340f2f /test/escape2.go
parentf1c409b98b8f9359d3e561a3a3f8d2ca514b1d44 (diff)
downloadgo-fd178d6a7e62796c71258ba155b957616be86ff4.tar.gz
go-fd178d6a7e62796c71258ba155b957616be86ff4.zip
cmd/gc: add way to specify 'noescape' for extern funcs
A new comment directive //go:noescape instructs the compiler that the following external (no body) func declaration should be treated as if none of its arguments escape to the heap. Fixes #4099. R=golang-dev, dave, minux.ma, daniel.morsing, remyoudompheng, adg, agl, iant CC=golang-dev https://golang.org/cl/7289048
Diffstat (limited to 'test/escape2.go')
-rw-r--r--test/escape2.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/escape2.go b/test/escape2.go
index 8e3aa4de74..9481619338 100644
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -1274,3 +1274,29 @@ func foo140() interface{} {
T: t,
}
}
+
+//go:noescape
+
+func F1([]byte)
+
+func F2([]byte)
+
+//go:noescape
+
+func F3(x []byte) // ERROR "F3 x does not escape"
+
+func F4(x []byte)
+
+func G() {
+ var buf1 [10]byte
+ F1(buf1[:]) // ERROR "buf1 does not escape"
+
+ var buf2 [10]byte // ERROR "moved to heap: buf2"
+ F2(buf2[:]) // ERROR "buf2 escapes to heap"
+
+ var buf3 [10]byte
+ F3(buf3[:]) // ERROR "buf3 does not escape"
+
+ var buf4 [10]byte // ERROR "moved to heap: buf4"
+ F4(buf4[:]) // ERROR "buf4 escapes to heap"
+}