1
0
mirror of https://github.com/golang/go synced 2024-11-26 23:41:37 -07:00
go/test/escape_struct_return.go
Matthew Dempsky e99e9a6e01 [dev.typeparams] cmd/compile: simplify ~r/~b naming
The compiler renames anonymous and blank result parameters to ~rN or
~bN, but the current semantics for computing N are rather annoying and
difficult to reproduce cleanly. They also lead to difficult to read
escape analysis results in tests.

This CL changes N to always be calculated as the parameter's index
within the function's result parameter tuple. E.g., if a function has
a single result, it will now always be named "~r0".

The normative change to this CL is fairly simple, but it requires
updating a lot of test expectations.

Change-Id: I58a3c94de00cb822cb94efe52d115531193c993c
Reviewed-on: https://go-review.googlesource.com/c/go/+/323010
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
2021-05-26 23:50:32 +00:00

75 lines
1.0 KiB
Go

// errorcheck -0 -m -l
// 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.
package foo
var Ssink *string
type U struct {
_sp *string
_spp **string
}
func A(sp *string, spp **string) U { // ERROR "leaking param: sp to result ~r0 level=0$" "leaking param: spp to result ~r0 level=0$"
return U{sp, spp}
}
func B(spp **string) U { // ERROR "leaking param: spp to result ~r0 level=0$"
return U{*spp, spp}
}
func tA1() {
s := "cat"
sp := &s
spp := &sp
u := A(sp, spp)
_ = u
println(s)
}
func tA2() {
s := "cat"
sp := &s
spp := &sp
u := A(sp, spp)
println(*u._sp)
}
func tA3() {
s := "cat"
sp := &s
spp := &sp
u := A(sp, spp)
println(**u._spp)
}
func tB1() {
s := "cat"
sp := &s
spp := &sp
u := B(spp)
_ = u
println(s)
}
func tB2() {
s := "cat"
sp := &s
spp := &sp
u := B(spp)
println(*u._sp)
}
func tB3() {
s := "cat"
sp := &s
spp := &sp
u := B(spp)
println(**u._spp)
}