]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/escape_closure.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / escape_closure.go
index 3b14027fa4be3b1514450236e7e5ed81cc251133..0b19d6f6e8fc9020bb5549ff80da1db38fcfd23e 100644 (file)
@@ -44,13 +44,13 @@ func ClosureCallArgs3() {
 
 func ClosureCallArgs4() {
        x := 0
-       _ = func(p *int) *int { // ERROR "leaking param: p to result ~r1" "func literal does not escape"
+       _ = func(p *int) *int { // ERROR "leaking param: p to result ~r0" "func literal does not escape"
                return p
        }(&x)
 }
 
 func ClosureCallArgs5() {
-       x := 0                     // ERROR "moved to heap: x"
+       x := 0 // ERROR "moved to heap: x"
        // TODO(mdempsky): We get "leaking param: p" here because the new escape analysis pass
        // can tell that p flows directly to sink, but it's a little weird. Re-evaluate.
        sink = func(p *int) *int { // ERROR "leaking param: p" "func literal does not escape"
@@ -111,7 +111,7 @@ func ClosureCallArgs11() {
 
 func ClosureCallArgs12() {
        x := 0
-       defer func(p *int) *int { // ERROR "leaking param: p to result ~r1" "func literal does not escape"
+       defer func(p *int) *int { // ERROR "leaking param: p to result ~r0" "func literal does not escape"
                return p
        }(&x)
 }
@@ -126,13 +126,13 @@ func ClosureCallArgs13() {
 func ClosureCallArgs14() {
        x := 0
        p := &x
-       _ = func(p **int) *int { // ERROR "leaking param: p to result ~r1 level=1" "func literal does not escape"
+       _ = func(p **int) *int { // ERROR "leaking param: p to result ~r0 level=1" "func literal does not escape"
                return *p
        }(&p)
 }
 
 func ClosureCallArgs15() {
-       x := 0                      // ERROR "moved to heap: x"
+       x := 0 // ERROR "moved to heap: x"
        p := &x
        sink = func(p **int) *int { // ERROR "leaking param content: p" "func literal does not escape"
                return *p
@@ -145,7 +145,7 @@ func ClosureLeak1(s string) string { // ERROR "s does not escape"
 }
 
 // See #14409 -- returning part of captured var leaks it.
-func ClosureLeak1a(a ...string) string { // ERROR "leaking param: a to result ~r1 level=1$"
+func ClosureLeak1a(a ...string) string { // ERROR "leaking param: a to result ~r0 level=1$"
        return func() string { // ERROR "func literal does not escape"
                return a[0]
        }()
@@ -164,3 +164,30 @@ func ClosureLeak2a(a ...string) string { // ERROR "leaking param content: a"
 func ClosureLeak2b(f func() string) string { // ERROR "f does not escape"
        return f()
 }
+
+func ClosureIndirect() {
+       f := func(p *int) {} // ERROR "p does not escape" "func literal does not escape"
+       f(new(int))          // ERROR "new\(int\) does not escape"
+
+       g := f
+       g(new(int)) // ERROR "new\(int\) does not escape"
+
+       h := nopFunc
+       h(new(int)) // ERROR "new\(int\) does not escape"
+}
+
+func nopFunc(p *int) {} // ERROR "p does not escape"
+
+func ClosureIndirect2() {
+       f := func(p *int) *int { return p } // ERROR "leaking param: p to result ~r0 level=0" "func literal does not escape"
+
+       f(new(int)) // ERROR "new\(int\) does not escape"
+
+       g := f
+       g(new(int)) // ERROR "new\(int\) does not escape"
+
+       h := nopFunc2
+       h(new(int)) // ERROR "new\(int\) does not escape"
+}
+
+func nopFunc2(p *int) *int { return p } // ERROR "leaking param: p to result ~r0 level=0"