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
commitf078711b412e9949d242e2bb54fc26d759232f5f (patch)
treecc2d67fd0e2165ee786c308d2be5d2fd31c6fbe9 /test/escape2.go
parent7e8bc474dbb9fdeda1a3e57121519084f2d673d8 (diff)
downloadgo-git-f078711b412e9949d242e2bb54fc26d759232f5f.tar.gz
cmd/gc: fix escape analysis for slice of array
Fixes #7931. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/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 220f9d91f1..382e8e6d64 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"
+}