1
0
mirror of https://github.com/golang/go synced 2024-11-27 04:52:17 -07:00
go/test/fixedbugs/issue42284.dir/a.go
Matthew Dempsky 063a91c0ab cmd/compile: fix recognition of unnamed return variables
In golang.org/cl/266199, I reused the existing code in inlining that
recognizes anonymous variables. However, it turns out that code
mistakenly recognizes anonymous return parameters as named when
inlining a function from the same package.

The issue is funcargs (which is only used for functions parsed from
source) synthesizes ~r names for anonymous return parameters, but
funcargs2 (which is only used for functions imported from export data)
does not.

This CL fixes the behavior so that anonymous return parameters are
handled identically whether a function is inlined within the same
package or across packages. It also adds a proper cross-package test
case demonstrating #33160 is fixed in both cases.

Change-Id: Iaa39a23f5666979a1f5ca6d09fc8c398e55b784c
Reviewed-on: https://go-review.googlesource.com/c/go/+/266719
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
2020-11-01 01:06:56 +00:00

31 lines
727 B
Go

// Copyright 2020 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.
package a
type I interface{ M() }
type T int
func (T) M() {} // ERROR "can inline T.M"
func E() I { // ERROR "can inline E"
return T(0) // ERROR "T\(0\) escapes to heap"
}
func F(i I) I { // ERROR "can inline F" "leaking param: i to result ~r1 level=0"
i = nil
return i
}
func g() {
h := E() // ERROR "inlining call to E" "T\(0\) does not escape"
h.M() // ERROR "devirtualizing h.M to T"
// BAD: T(0) could be stack allocated.
i := F(T(0)) // ERROR "inlining call to F" "T\(0\) escapes to heap"
// Testing that we do NOT devirtualize here:
i.M()
}