| // Copyright 2015 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // Test escape analysis for function parameters. |
| // In this test almost everything is BAD except the simplest cases |
| // where input directly flows to output. |
| func f(buf []byte) []byte { // ERROR "leaking param: buf to result ~r1 level=0$" |
| var x [32]byte // ERROR "moved to heap: x$" |
| g(&f(x[:])[0]) // ERROR "&f\(x\[:\]\)\[0\] escapes to heap$" "x escapes to heap$" |
| func walk(np **Node) int { // ERROR "leaking param content: np" |
| wl := walk(&n.left) // ERROR "walk &n.left does not escape" |
| wr := walk(&n.right) // ERROR "walk &n.right does not escape" |
| n.left, n.right = n.right, n.left |
| // Test for bug where func var f used prototype's escape analysis results. |
| func prototype(xyz []string) {} // ERROR "prototype xyz does not escape" |
| f = func(ss []string) { got = append(got, ss) } // ERROR "leaking param: ss" "func literal does not escape" |
| f([]string{s}) // ERROR "\[\]string literal escapes to heap" |