summaryrefslogtreecommitdiff
path: root/test/escape2.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-05-12 14:45:05 -0400
committerRuss Cox <rsc@golang.org>2014-05-12 14:45:05 -0400
commitfc46eb95614bccdfa01f448fc78acd1ee82adcc1 (patch)
tree84fafc4256831358d2dec69dc21a1b686fa8226e /test/escape2.go
parent53b23f145d7f42981061ec448ce52046c4fd8261 (diff)
downloadgo-fc46eb95614bccdfa01f448fc78acd1ee82adcc1.tar.gz
cmd/gc: fix escape analysis for slice of array
Fixes issue 7931. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://codereview.appspot.com/100390044
Diffstat (limited to 'test/escape2.go')
-rw-r--r--test/escape2.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/escape2.go b/test/escape2.go
index 220f9d91f..382e8e6d6 100644
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -1411,3 +1411,35 @@ func foo150(x ...byte) { // ERROR "leaking param: x"
func bar150() {
foo150(1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
}
+
+// issue 7931: bad handling of slice of array
+
+var save151 *int
+
+func foo151(x *int) { // ERROR "leaking param: x"
+ save151 = x
+}
+
+func bar151() {
+ var a [64]int // ERROR "moved to heap: a"
+ a[4] = 101
+ foo151(&(&a)[4:8][0]) // ERROR "&\(&a\)\[4:8\]\[0\] escapes to heap" "&a escapes to heap"
+}
+
+func bar151b() {
+ var a [10]int // ERROR "moved to heap: a"
+ b := a[:] // ERROR "a escapes to heap"
+ foo151(&b[4:8][0]) // ERROR "&b\[4:8\]\[0\] escapes to heap"
+}
+
+func bar151c() {
+ var a [64]int // ERROR "moved to heap: a"
+ a[4] = 101
+ foo151(&(&a)[4:8:8][0]) // ERROR "&\(&a\)\[4:8:8\]\[0\] escapes to heap" "&a escapes to heap"
+}
+
+func bar151d() {
+ var a [10]int // ERROR "moved to heap: a"
+ b := a[:] // ERROR "a escapes to heap"
+ foo151(&b[4:8:8][0]) // ERROR "&b\[4:8:8\]\[0\] escapes to heap"
+}