]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: fix invalid positions for sink nodes in esc.go
authorIskander Sharipov <iskander.sharipov@intel.com>
Tue, 14 Aug 2018 16:22:16 +0000 (19:22 +0300)
committerCherry Zhang <cherryyz@google.com>
Mon, 3 Sep 2018 16:46:59 +0000 (16:46 +0000)
Make OAS2 and OAS2FUNC sink locations point to the assignment position,
not the nth LHS position.

Fixes #26987

Change-Id: Ibeb9df2da754da8b6638fe1e49e813f37515c13c
Reviewed-on: https://go-review.googlesource.com/129315
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/esc.go
test/escape_because.go

index a852e0a3d0f7742200f9435ffd6574a8c1ae7f66..99f046ad216df47d02f50a20fcc66def9d7dbe60 100644 (file)
@@ -886,8 +886,9 @@ opSwitch:
        case OAS2: // x,y = a,b
                if n.List.Len() == n.Rlist.Len() {
                        rs := n.Rlist.Slice()
+                       where := n
                        for i, n := range n.List.Slice() {
-                               e.escassignWhyWhere(n, rs[i], "assign-pair", n)
+                               e.escassignWhyWhere(n, rs[i], "assign-pair", where)
                        }
                }
 
@@ -928,11 +929,12 @@ opSwitch:
                // esccall already done on n.Rlist.First(). tie it's Retval to n.List
        case OAS2FUNC: // x,y = f()
                rs := e.nodeEscState(n.Rlist.First()).Retval.Slice()
+               where := n
                for i, n := range n.List.Slice() {
                        if i >= len(rs) {
                                break
                        }
-                       e.escassignWhyWhere(n, rs[i], "assign-pair-func-call", n)
+                       e.escassignWhyWhere(n, rs[i], "assign-pair-func-call", where)
                }
                if n.List.Len() != len(rs) {
                        Fatalf("esc oas2func")
index c7548fc677a5ef4f003c39988de9a17617d827a4..0f87f1446f6d69922b39497e8fe101880ad76605 100644 (file)
@@ -125,6 +125,24 @@ func f14() {
        _, _ = s1, s2
 }
 
+func leakParams(p1, p2 *int) (*int, *int) { // ERROR "leaking param: p1 to result ~r2 level=0$" "from ~r2 \(return\) at escape_because.go:129$" "leaking param: p2 to result ~r3 level=0$" "from ~r3 \(return\) at escape_because.go:129$"
+       return p1, p2
+}
+
+func leakThroughOAS2() {
+       // See #26987.
+       i := 0              // ERROR "moved to heap: i$"
+       j := 0              // ERROR "moved to heap: j$"
+       sink, sink = &i, &j // ERROR "&i escapes to heap$" "from sink \(assign-pair\) at escape_because.go:136$" "from &i \(interface-converted\) at escape_because.go:136$" "&j escapes to heap$" "from &j \(interface-converted\) at escape_because.go:136"
+}
+
+func leakThroughOAS2FUNC() {
+       // See #26987.
+       i := 0 // ERROR "moved to heap: i$"
+       j := 0
+       sink, _ = leakParams(&i, &j) // ERROR "&i escapes to heap$" "&j does not escape$" "from .out0 \(passed-to-and-returned-from-call\) at escape_because.go:143$" "from sink \(assign-pair-func-call\) at escape_because.go:143$"
+}
+
 // The list below is all of the why-escapes messages seen building the escape analysis tests.
 /*
    for i in escape*go ; do echo compile $i; go build -gcflags '-l -m -m' $i >& `basename $i .go`.log ; done