diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 020ca9b40c6..85561cdb276 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -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) diff --git a/test/escape2.go b/test/escape2.go index c048f1b7aa0..46cfde4a94c 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -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] +} diff --git a/test/escape2n.go b/test/escape2n.go index f1481c1a361..c32877321fa 100644 --- a/test/escape2n.go +++ b/test/escape2n.go @@ -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] +}