3 // Copyright 2015 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test escape analysis for function parameters.
9 // In this test almost everything is BAD except the simplest cases
10 // where input directly flows to output.
18 func bar(a, b *string) U { // ERROR "leaking param: a to result ~r2 level=0$" "leaking param: b to result ~r2 level=0$"
22 func foo(x U) U { // ERROR "leaking param: x to result ~r1 level=0$"
26 func bff(a, b *string) U { // ERROR "leaking param: a to result ~r2 level=0$" "leaking param: b to result ~r2 level=0$"
27 return foo(foo(bar(a, b)))
30 func tbff1() *string {
32 b := "dog" // ERROR "moved to heap: b$"
33 u := bff(&a, &b) // ERROR "tbff1 &a does not escape$" "tbff1 &b does not escape$"
35 return &b // ERROR "&b escapes to heap$"
38 // BAD: need fine-grained analysis to track u[0] and u[1] differently.
39 func tbff2() *string {
40 a := "cat" // ERROR "moved to heap: a$"
41 b := "dog" // ERROR "moved to heap: b$"
42 u := bff(&a, &b) // ERROR "&a escapes to heap$" "&b escapes to heap$"
47 func car(x U) *string { // ERROR "leaking param: x to result ~r1 level=0$"
51 // BAD: need fine-grained analysis to track x[0] and x[1] differently.
52 func fun(x U, y *string) *string { // ERROR "leaking param: x to result ~r2 level=0$" "leaking param: y to result ~r2 level=0$"
57 func fup(x *U, y *string) *string { // ERROR "leaking param: x to result ~r2 level=1$" "leaking param: y$"
58 x[0] = y // leaking y to heap is intended
62 // BAD: would be nice to record that *y (content) is what leaks, not y itself
63 func fum(x *U, y **string) *string { // ERROR "leaking param: x to result ~r2 level=1$" "leaking param content: y$"
68 // BAD: would be nice to record that y[0] (content) is what leaks, not y itself
69 func fuo(x *U, y *U) *string { // ERROR "leaking param: x to result ~r2 level=1$" "leaking param content: y$"