]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/escape_array.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / escape_array.go
index 0204c690cddcccc8ccd89b769b8b6326e2f29958..83062c9436e71d2a1ed9462633b2e8d829a63197 100644 (file)
@@ -12,56 +12,56 @@ var Ssink *string
 
 type U [2]*string
 
-func bar(a, b *string) U { // ERROR "leaking param: a to result ~r2 level=0$" "leaking param: b to result ~r2 level=0$"
+func bar(a, b *string) U { // ERROR "leaking param: a to result ~r0 level=0$" "leaking param: b to result ~r0 level=0$"
        return U{a, b}
 }
 
-func foo(x U) U { // ERROR "leaking param: x to result ~r1 level=0$"
+func foo(x U) U { // ERROR "leaking param: x to result ~r0 level=0$"
        return U{x[1], x[0]}
 }
 
-func bff(a, b *string) U { // ERROR "leaking param: a to result ~r2 level=0$" "leaking param: b to result ~r2 level=0$"
+func bff(a, b *string) U { // ERROR "leaking param: a to result ~r0 level=0$" "leaking param: b to result ~r0 level=0$"
        return foo(foo(bar(a, b)))
 }
 
 func tbff1() *string {
        a := "cat"
-       b := "dog"       // ERROR "moved to heap: b$"
-       u := bff(&a, &b) // ERROR "tbff1 &a does not escape$" "tbff1 &b does not escape$"
+       b := "dog" // ERROR "moved to heap: b$"
+       u := bff(&a, &b)
        _ = u[0]
-       return &b // ERROR "&b escapes to heap$"
+       return &b
 }
 
 // BAD: need fine-grained analysis to track u[0] and u[1] differently.
 func tbff2() *string {
-       a := "cat"       // ERROR "moved to heap: a$"
-       b := "dog"       // ERROR "moved to heap: b$"
-       u := bff(&a, &b) // ERROR "&a escapes to heap$" "&b escapes to heap$"
+       a := "cat" // ERROR "moved to heap: a$"
+       b := "dog" // ERROR "moved to heap: b$"
+       u := bff(&a, &b)
        _ = u[0]
        return u[1]
 }
 
-func car(x U) *string { // ERROR "leaking param: x to result ~r1 level=0$"
+func car(x U) *string { // ERROR "leaking param: x to result ~r0 level=0$"
        return x[0]
 }
 
 // BAD: need fine-grained analysis to track x[0] and x[1] differently.
-func fun(x U, y *string) *string { // ERROR "leaking param: x to result ~r2 level=0$" "leaking param: y to result ~r2 level=0$"
+func fun(x U, y *string) *string { // ERROR "leaking param: x to result ~r0 level=0$" "leaking param: y to result ~r0 level=0$"
        x[0] = y
        return x[1]
 }
 
-func fup(x *U, y *string) *string { // ERROR "leaking param: x to result ~r2 level=1$" "leaking param: y$"
+func fup(x *U, y *string) *string { // ERROR "leaking param: x to result ~r0 level=1$" "leaking param: y$"
        x[0] = y // leaking y to heap is intended
        return x[1]
 }
 
-func fum(x *U, y **string) *string { // ERROR "leaking param: x to result ~r2 level=1$" "leaking param content: y$"
+func fum(x *U, y **string) *string { // ERROR "leaking param: x to result ~r0 level=1$" "leaking param content: y$"
        x[0] = *y
        return x[1]
 }
 
-func fuo(x *U, y *U) *string { // ERROR "leaking param: x to result ~r2 level=1$" "leaking param content: y$"
+func fuo(x *U, y *U) *string { // ERROR "leaking param: x to result ~r0 level=1$" "leaking param content: y$"
        x[0] = y[0]
        return x[1]
 }
@@ -71,7 +71,7 @@ func fuo(x *U, y *U) *string { // ERROR "leaking param: x to result ~r2 level=1$
 // pointers stored in small array literals do not escape;
 // large array literals are heap allocated;
 // pointers stored in large array literals escape.
-func hugeLeaks1(x **string, y **string) { // ERROR "leaking param content: x" "hugeLeaks1 y does not escape" "mark escaped content: x"
+func hugeLeaks1(x **string, y **string) { // ERROR "leaking param content: x" "y does not escape"
        a := [10]*string{*y}
        _ = a
        // 4 x 4,000,000 exceeds MaxStackVarSize, therefore it must be heap allocated if pointers are 4 bytes or larger.
@@ -79,7 +79,7 @@ func hugeLeaks1(x **string, y **string) { // ERROR "leaking param content: x" "h
        _ = b
 }
 
-func hugeLeaks2(x *string, y *string) { // ERROR "leaking param: x" "hugeLeaks2 y does not escape"
+func hugeLeaks2(x *string, y *string) { // ERROR "leaking param: x" "y does not escape"
        a := [10]*string{y}
        _ = a
        // 4 x 4,000,000 exceeds MaxStackVarSize, therefore it must be heap allocated if pointers are 4 bytes or larger.
@@ -120,3 +120,10 @@ func doesMakeSlice(x *string, y *string) { // ERROR "leaking param: x" "leaking
        b := make([]*string, 65537) // ERROR "make\(\[\]\*string, 65537\) escapes to heap"
        b[0] = y
 }
+
+func nonconstArray() {
+       n := 32
+       s1 := make([]int, n)    // ERROR "make\(\[\]int, n\) escapes to heap"
+       s2 := make([]int, 0, n) // ERROR "make\(\[\]int, 0, n\) escapes to heap"
+       _, _ = s1, s2
+}