1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:44:39 -07:00

cmd/gc: fix escape analysis bug

Was not handling &x.y[0] and &x.y.z correctly where
y is an array or struct-valued field (not a pointer).

R=ken2
CC=golang-dev
https://golang.org/cl/6551059
This commit is contained in:
Russ Cox 2012-09-24 15:53:12 -04:00
parent c7e0b8baa6
commit 54af752865
3 changed files with 43 additions and 1 deletions

View File

@ -926,9 +926,15 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
}
break;
case ODOT:
escwalk(e, level, dst, src->left);
break;
case OINDEX:
if(isfixedarray(src->type))
if(isfixedarray(src->left->type)) {
escwalk(e, level, dst, src->left);
break;
}
// fall through
case OSLICE:
case ODOTPTR:

View File

@ -1211,3 +1211,21 @@ func foo137() {
}()
}()
}
func foo138() *byte {
type T struct {
x [1]byte
}
t := new(T) // ERROR "new.T. escapes to heap"
return &t.x[0] // ERROR "&t.x.0. escapes to heap"
}
func foo139() *byte {
type T struct {
x struct {
y byte
}
}
t := new(T) // ERROR "new.T. escapes to heap"
return &t.x.y // ERROR "&t.x.y escapes to heap"
}

View File

@ -37,3 +37,21 @@ func f2() {} // ERROR "can inline f2"
// No inline for panic, recover.
func f3() { panic(1) }
func f4() { recover() }
func f5() *byte {
type T struct {
x [1]byte
}
t := new(T) // ERROR "new.T. escapes to heap"
return &t.x[0] // ERROR "&t.x.0. escapes to heap"
}
func f6() *byte {
type T struct {
x struct {
y byte
}
}
t := new(T) // ERROR "new.T. escapes to heap"
return &t.x.y // ERROR "&t.x.y escapes to heap"
}