aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-10-30 12:58:28 -0700
committerMatthew Dempsky <mdempsky@google.com>2020-11-01 01:06:56 +0000
commit063a91c0abef445154df1ba34ffb500eeccfe8bc (patch)
tree96be33fdceba41bed0a6a1efb0c09848decf17f4 /test
parent715d4e2e014fa54f527ee109f26a31f941196381 (diff)
downloadgo-063a91c0abef445154df1ba34ffb500eeccfe8bc.tar.gz
go-063a91c0abef445154df1ba34ffb500eeccfe8bc.zip
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>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue42284.dir/a.go9
-rw-r--r--test/fixedbugs/issue42284.dir/b.go5
2 files changed, 12 insertions, 2 deletions
diff --git a/test/fixedbugs/issue42284.dir/a.go b/test/fixedbugs/issue42284.dir/a.go
index e1271af32d..ffe9310be3 100644
--- a/test/fixedbugs/issue42284.dir/a.go
+++ b/test/fixedbugs/issue42284.dir/a.go
@@ -9,12 +9,19 @@ 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() { // ERROR "can inline g"
+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"
diff --git a/test/fixedbugs/issue42284.dir/b.go b/test/fixedbugs/issue42284.dir/b.go
index 3305166db0..652aa32122 100644
--- a/test/fixedbugs/issue42284.dir/b.go
+++ b/test/fixedbugs/issue42284.dir/b.go
@@ -6,7 +6,10 @@ package b
import "./a"
-func g() { // ERROR "can inline g"
+func g() {
+ h := a.E() // ERROR "inlining call to a.E" "a.I\(a.T\(0\)\) does not escape"
+ h.M() // ERROR "devirtualizing h.M to a.T"
+
// BAD: T(0) could be stack allocated.
i := a.F(a.T(0)) // ERROR "inlining call to a.F" "a.T\(0\) escapes to heap"