]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: handle copy in escape analysis
authorRuss Cox <rsc@golang.org>
Wed, 24 Jun 2015 21:31:57 +0000 (17:31 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 24 Jun 2015 22:22:55 +0000 (22:22 +0000)
Somehow we missed this!
Fixes #11387.

Change-Id: Ida08fe52eff7da2ef7765b4cf35a39a301420c43
Reviewed-on: https://go-review.googlesource.com/11460
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/gc/esc.go
test/escape2.go
test/escape2n.go

index 020ca9b40c606a66c23c3b15ee6b3b6121bc30e3..85561cdb27625c25185560b3896aac69b95b395f 100644 (file)
@@ -809,6 +809,9 @@ func esc(e *EscState, n *Node, up *Node) {
                }
                escassignDereference(e, &e.theSink, n.List.N) // The original elements are now leaked, too
 
+       case OCOPY:
+               escassignDereference(e, &e.theSink, n.Right) // lose track of assign of dereference
+
        case OCONV, OCONVNOP:
                escassign(e, n, n.Left)
 
index c048f1b7aa01222d24ff86cc5e0799d01dab5d09..46cfde4a94c56fb61ef722d8558fdd1b8fbf4cf5 100644 (file)
@@ -858,8 +858,8 @@ func foo103(m [1]*int, x *int) { // ERROR "foo103 m does not escape$" "foo103 x
 
 var y []*int
 
-// does not leak x
-func foo104(x []*int) { // ERROR "foo104 x does not escape$"
+// does not leak x but does leak content
+func foo104(x []*int) { // ERROR "leaking param content: x"
        copy(y, x)
 }
 
@@ -1820,3 +1820,11 @@ func issue10353b() {
        }
        _ = f
 }
+
+func issue11387(x int) func() int {
+       f := func() int { return x }    // ERROR "func literal escapes to heap"
+       slice1 := []func() int{f}       // ERROR "\[\].* does not escape"
+       slice2 := make([]func() int, 1) // ERROR "make\(.*\) does not escape"
+       copy(slice2, slice1)
+       return slice2[0]
+}
index f1481c1a361ada3ea32b09ef9f7f3a73e2503114..c32877321fa7295691e5474929547848881915a7 100644 (file)
@@ -858,8 +858,8 @@ func foo103(m [1]*int, x *int) { // ERROR "foo103 m does not escape$" "foo103 x
 
 var y []*int
 
-// does not leak x
-func foo104(x []*int) { // ERROR "foo104 x does not escape$"
+// does not leak x but does leak content
+func foo104(x []*int) { // ERROR "leaking param content: x"
        copy(y, x)
 }
 
@@ -1820,3 +1820,11 @@ func issue10353b() {
        }
        _ = f
 }
+
+func issue11387(x int) func() int {
+       f := func() int { return x }    // ERROR "func literal escapes to heap"
+       slice1 := []func() int{f}       // ERROR "\[\].* does not escape"
+       slice2 := make([]func() int, 1) // ERROR "make\(.*\) does not escape"
+       copy(slice2, slice1)
+       return slice2[0]
+}