FAQ
Reviewers: ken2,

Message:
Hello ken2 (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
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).

Please review this at http://codereview.appspot.com/6551059/

Affected files:
M src/cmd/gc/esc.c
M test/escape2.go
M test/escape4.go


Index: src/cmd/gc/esc.c
===================================================================
--- a/src/cmd/gc/esc.c
+++ b/src/cmd/gc/esc.c
@@ -926,9 +926,15 @@
}
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: test/escape2.go
===================================================================
--- a/test/escape2.go
+++ b/test/escape2.go
@@ -1211,3 +1211,21 @@
}()
}()
}
+
+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: test/escape4.go
===================================================================
--- a/test/escape4.go
+++ b/test/escape4.go
@@ -37,3 +37,21 @@
// 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"
+}

Search Discussions

  • Rsc at Sep 24, 2012 at 7:53 pm
    *** Submitted as
    http://code.google.com/p/go/source/detail?r=0ece4ff29314 ***

    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
    http://codereview.appspot.com/6551059


    http://codereview.appspot.com/6551059/
  • Ken at Sep 24, 2012 at 8:07 pm
  • Rémy Oudompheng at Sep 24, 2012 at 8:38 pm
    I suppose the bug is present in Go 1.0.3 ?
  • Russ Cox at Sep 24, 2012 at 9:56 pm

    On Mon, Sep 24, 2012 at 4:10 PM, Rémy Oudompheng wrote:
    I suppose the bug is present in Go 1.0.3 ?
    Yes but as far as I know no one has run into it. It is somewhat
    compensated for by the fact that &T{} is always treated as escaping
    and by the fact that most programs do not allocate a big struct and
    then return only a pointer to a piece of it. If we do a Go 1.0.4 we'd
    want to include it, but I hope we won't do that.

    Russ

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 24, '12 at 7:53p
activeSep 24, '12 at 9:56p
posts5
users3
websitegolang.org

3 users in discussion

Russ Cox: 3 posts Rémy Oudompheng: 1 post Ken: 1 post

People

Translate

site design / logo © 2022 Grokbase