Commit f078711b authored by Russ Cox's avatar Russ Cox

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
parent 7e8bc474
...@@ -767,8 +767,8 @@ escassign(EscState *e, Node *dst, Node *src) ...@@ -767,8 +767,8 @@ escassign(EscState *e, Node *dst, Node *src)
case ODOTTYPE: case ODOTTYPE:
case ODOTTYPE2: case ODOTTYPE2:
case OSLICE: case OSLICE:
case OSLICEARR:
case OSLICE3: case OSLICE3:
case OSLICEARR:
case OSLICE3ARR: case OSLICE3ARR:
// Conversions, field access, slice all preserve the input value. // Conversions, field access, slice all preserve the input value.
escassign(e, dst, src->left); escassign(e, dst, src->left);
...@@ -1155,6 +1155,10 @@ escwalk(EscState *e, int level, Node *dst, Node *src) ...@@ -1155,6 +1155,10 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
break; break;
case ODOT: case ODOT:
case OSLICE:
case OSLICEARR:
case OSLICE3:
case OSLICE3ARR:
escwalk(e, level, dst, src->left); escwalk(e, level, dst, src->left);
break; break;
...@@ -1164,7 +1168,6 @@ escwalk(EscState *e, int level, Node *dst, Node *src) ...@@ -1164,7 +1168,6 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
break; break;
} }
// fall through // fall through
case OSLICE:
case ODOTPTR: case ODOTPTR:
case OINDEXMAP: case OINDEXMAP:
case OIND: case OIND:
......
...@@ -1411,3 +1411,35 @@ func foo150(x ...byte) { // ERROR "leaking param: x" ...@@ -1411,3 +1411,35 @@ func foo150(x ...byte) { // ERROR "leaking param: x"
func bar150() { func bar150() {
foo150(1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" 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"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment