mirror of
https://github.com/golang/go
synced 2024-11-11 22:20:22 -07:00
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
This commit is contained in:
parent
7e8bc474db
commit
f078711b41
@ -767,8 +767,8 @@ escassign(EscState *e, Node *dst, Node *src)
|
||||
case ODOTTYPE:
|
||||
case ODOTTYPE2:
|
||||
case OSLICE:
|
||||
case OSLICEARR:
|
||||
case OSLICE3:
|
||||
case OSLICEARR:
|
||||
case OSLICE3ARR:
|
||||
// Conversions, field access, slice all preserve the input value.
|
||||
escassign(e, dst, src->left);
|
||||
@ -1155,6 +1155,10 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
|
||||
break;
|
||||
|
||||
case ODOT:
|
||||
case OSLICE:
|
||||
case OSLICEARR:
|
||||
case OSLICE3:
|
||||
case OSLICE3ARR:
|
||||
escwalk(e, level, dst, src->left);
|
||||
break;
|
||||
|
||||
@ -1164,7 +1168,6 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
case OSLICE:
|
||||
case ODOTPTR:
|
||||
case OINDEXMAP:
|
||||
case OIND:
|
||||
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user