aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-10-29 13:30:54 -0700
committerMatthew Dempsky <mdempsky@google.com>2020-10-30 00:47:37 +0000
commite62adb1c0b8e7ca49eefc70389fbb9f739d6e32c (patch)
tree3279fe2cb4d0fc2bc2e237643f965835da3fd062 /test
parentfaa44268116df045813e36c9b57d7309b74f14f6 (diff)
downloadgo-e62adb1c0b8e7ca49eefc70389fbb9f739d6e32c.tar.gz
go-e62adb1c0b8e7ca49eefc70389fbb9f739d6e32c.zip
cmd/compile: fix devirtualization of promoted interface methods
A method selector expression can pick out a method or promoted method (represented by ODOTMETH), but it can also pick out an interface method from an embedded interface-typed field (represented by ODOTINTER). In the case that we're picking out an interface method, we're not able to fully devirtualize the method call. However, we're still able to improve escape analysis somewhat. E.g., the included test case demonstrates that we can optimize "i.M()" to "i.(T).I.M()", which means the T literal can be stack allocated instead of heap allocated. Fixes #42279. Change-Id: Ifa21d19011e2f008d84f9624b7055b4676b6d188 Reviewed-on: https://go-review.googlesource.com/c/go/+/266300 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/escape_iface.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/escape_iface.go b/test/escape_iface.go
index 5a232fdbd4..dba08e3cb3 100644
--- a/test/escape_iface.go
+++ b/test/escape_iface.go
@@ -255,3 +255,11 @@ func dotTypeEscape2() { // #13805, #15796
sink, *(&ok) = y.(*int)
}
}
+
+func issue42279() {
+ type I interface{ M() }
+ type T struct{ I }
+
+ var i I = T{} // ERROR "T\{\} does not escape"
+ i.M() // ERROR "partially devirtualizing i.M to T"
+}