]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix escape analysis bug
authorRuss Cox <rsc@golang.org>
Mon, 24 Sep 2012 19:53:12 +0000 (15:53 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 24 Sep 2012 19:53:12 +0000 (15:53 -0400)
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

src/cmd/gc/esc.c
test/escape2.go
test/escape4.go

index bd197ab23e8f57c3e280237d8ea2848950a252c4..c5faa041c8c3d464502ad976ceea578f9af6b378 100644 (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:
index 8f48ef7bd6714cf7341ad1f0e3249a4a98e8fb39..8db12d99131f77862e1dec65195eff60a8eca12e 100644 (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"
+}
index cc3ac78f04d2cd8c0597fbe6eccc6f654f6f643d..83bc8eb123dd976c93d2dfb3fefc131fb56efde1 100644 (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"
+}