From: Russ Cox Date: Mon, 24 Sep 2012 19:53:12 +0000 (-0400) Subject: cmd/gc: fix escape analysis bug X-Git-Tag: go1.1rc2~2339 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=54af752865d4759eb49437904f3a2d04d3779cc8;p=gostls13.git 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 --- diff --git a/src/cmd/gc/esc.c b/src/cmd/gc/esc.c index bd197ab23e..c5faa041c8 100644 --- a/src/cmd/gc/esc.c +++ b/src/cmd/gc/esc.c @@ -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: diff --git a/test/escape2.go b/test/escape2.go index 8f48ef7bd6..8db12d9913 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -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" +} diff --git a/test/escape4.go b/test/escape4.go index cc3ac78f04..83bc8eb123 100644 --- a/test/escape4.go +++ b/test/escape4.go @@ -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" +}