]> Cypherpunks.ru repositories - gostls13.git/commitdiff
test: add additional ... tests for escape analysis
authorDmitry Vyukov <dvyukov@google.com>
Thu, 19 Feb 2015 14:54:55 +0000 (17:54 +0300)
committerDmitry Vyukov <dvyukov@google.com>
Sat, 28 Mar 2015 13:07:19 +0000 (13:07 +0000)
False positives (var incorrectly escapes) are marked with BAD.

Change-Id: I646a29ffe24d963c63db09cba81dbc101d7c7242
Reviewed-on: https://go-review.googlesource.com/5296
Reviewed-by: Keith Randall <khr@golang.org>
test/escape2.go
test/escape2n.go

index 3fd62d1dfca1d03f197fe3ee3486b075503ec000..69c5913db0013f97c9f534125e1116eef85dde82 100644 (file)
@@ -610,11 +610,11 @@ func foo74c() {
        }
 }
 
-func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leaking param: y"
+func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leaking param: y to result ~r2"
        return y
 }
 
-func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not escape" "leaking param: x"
+func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not escape" "leaking param: x to result ~r2"
        return &x[0] // ERROR "&x.0. escapes to heap"
 }
 
@@ -635,10 +635,16 @@ func foo75aesc(z *int) { // ERROR "z does not escape"
        *ppi = myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
 }
 
+func foo75aesc1(z *int) { // ERROR "z does not escape"
+       sink = myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
+}
+
+// BAD: z does not escape here
 func foo76(z *int) { // ERROR "leaking param: z"
        myprint(nil, z) // ERROR "[.][.][.] argument does not escape"
 }
 
+// BAD: z does not escape here
 func foo76a(z *int) { // ERROR "leaking param: z"
        myprint1(nil, z) // ERROR "[.][.][.] argument does not escape"
 }
@@ -685,6 +691,20 @@ func foo77b(z []interface{}) { // ERROR "leaking param: z"
        *ppi = myprint1(nil, z...)
 }
 
+func foo77c(z []interface{}) { // ERROR "leaking param: z"
+       sink = myprint1(nil, z...)
+}
+
+func dotdotdot() {
+       // BAD: i should not escape here
+       i := 0           // ERROR "moved to heap: i"
+       myprint(nil, &i) // ERROR "&i escapes to heap" "\.\.\. argument does not escape"
+
+       // BAD: j should not escape here
+       j := 0            // ERROR "moved to heap: j"
+       myprint1(nil, &j) // ERROR "&j escapes to heap" "\.\.\. argument does not escape"
+}
+
 func foo78(z int) *int { // ERROR "moved to heap: z"
        return &z // ERROR "&z escapes to heap"
 }
index e9dd7b984e5d18563d046e9347abaa48b24659a6..5e58537111591f7034d30e8d8512609a3f69f54b 100644 (file)
@@ -610,11 +610,11 @@ func foo74c() {
        }
 }
 
-func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leaking param: y"
+func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leaking param: y to result ~r2"
        return y
 }
 
-func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not escape" "leaking param: x"
+func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not escape" "leaking param: x to result ~r2"
        return &x[0] // ERROR "&x.0. escapes to heap"
 }
 
@@ -635,10 +635,16 @@ func foo75aesc(z *int) { // ERROR "z does not escape"
        *ppi = myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
 }
 
+func foo75aesc1(z *int) { // ERROR "z does not escape"
+       sink = myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
+}
+
+// BAD: z does not escape here
 func foo76(z *int) { // ERROR "leaking param: z"
        myprint(nil, z) // ERROR "[.][.][.] argument does not escape"
 }
 
+// BAD: z does not escape here
 func foo76a(z *int) { // ERROR "leaking param: z"
        myprint1(nil, z) // ERROR "[.][.][.] argument does not escape"
 }
@@ -685,6 +691,20 @@ func foo77b(z []interface{}) { // ERROR "leaking param: z"
        *ppi = myprint1(nil, z...)
 }
 
+func foo77c(z []interface{}) { // ERROR "leaking param: z"
+       sink = myprint1(nil, z...)
+}
+
+func dotdotdot() {
+       // BAD: i should not escape here
+       i := 0           // ERROR "moved to heap: i"
+       myprint(nil, &i) // ERROR "&i escapes to heap" "\.\.\. argument does not escape"
+
+       // BAD: j should not escape here
+       j := 0            // ERROR "moved to heap: j"
+       myprint1(nil, &j) // ERROR "&j escapes to heap" "\.\.\. argument does not escape"
+}
+
 func foo78(z int) *int { // ERROR "moved to heap: z"
        return &z // ERROR "&z escapes to heap"
 }