]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix escape analysis for slice of array
authorRuss Cox <rsc@golang.org>
Mon, 12 May 2014 18:45:05 +0000 (14:45 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 12 May 2014 18:45:05 +0000 (14:45 -0400)
Fixes #7931.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/100390044

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

index 028163abbfabf482467393a6f5479d4dd89042bc..4091682485bf2507ab322119d3e2383f748d4c2f 100644 (file)
@@ -767,8 +767,8 @@ escassign(EscState *e, Node *dst, Node *src)
        case ODOTTYPE:
        case ODOTTYPE2:
        case OSLICE:
-       case OSLICEARR:
        case OSLICE3:
+       case OSLICEARR:
        case OSLICE3ARR:
                // Conversions, field access, slice all preserve the input value.
                escassign(e, dst, src->left);
@@ -1155,6 +1155,10 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
                break;
 
        case ODOT:
+       case OSLICE:
+       case OSLICEARR:
+       case OSLICE3:
+       case OSLICE3ARR:
                escwalk(e, level, dst, src->left);
                break;
 
@@ -1164,7 +1168,6 @@ escwalk(EscState *e, int level, Node *dst, Node *src)
                        break;
                }
                // fall through
-       case OSLICE:
        case ODOTPTR:
        case OINDEXMAP:
        case OIND:
index 220f9d91f1124ba4445b5ce233324e83b118ba6a..382e8e6d6467039ed4e3b8a67258cee63a7f70bb 100644 (file)
@@ -1411,3 +1411,35 @@ func foo150(x ...byte) { // ERROR "leaking param: x"
 func bar150() {
        foo150(1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
 }
+
+// issue 7931: bad handling of slice of array
+
+var save151 *int
+
+func foo151(x *int) { // ERROR "leaking param: x"
+       save151 = x
+}
+
+func bar151() {
+       var a [64]int // ERROR "moved to heap: a"
+       a[4] = 101
+       foo151(&(&a)[4:8][0]) // ERROR "&\(&a\)\[4:8\]\[0\] escapes to heap" "&a escapes to heap"
+}
+
+func bar151b() {
+       var a [10]int      // ERROR "moved to heap: a"
+       b := a[:]          // ERROR "a escapes to heap"
+       foo151(&b[4:8][0]) // ERROR "&b\[4:8\]\[0\] escapes to heap"
+}
+
+func bar151c() {
+       var a [64]int // ERROR "moved to heap: a"
+       a[4] = 101
+       foo151(&(&a)[4:8:8][0]) // ERROR "&\(&a\)\[4:8:8\]\[0\] escapes to heap" "&a escapes to heap"
+}
+
+func bar151d() {
+       var a [10]int        // ERROR "moved to heap: a"
+       b := a[:]            // ERROR "a escapes to heap"
+       foo151(&b[4:8:8][0]) // ERROR "&b\[4:8:8\]\[0\] escapes to heap"
+}