aboutsummaryrefslogtreecommitdiff
path: root/test/codegen
diff options
context:
space:
mode:
authorMateusz Poliwczak <mpoliwczak34@gmail.com>2025-02-16 17:24:19 +0000
committerGopher Robot <gobot@golang.org>2025-02-19 13:39:00 -0800
commit43e6525986d70e7f3d3af394ee442d3390568c01 (patch)
tree12aec531e289d6ce34f6b6e8ccef65c4de7188ad /test/codegen
parentba3f568988bff69b3d00cd6ca76ab536eacbea48 (diff)
downloadgo-43e6525986d70e7f3d3af394ee442d3390568c01.tar.xz
cmd/compile: load properly constant values from itabs
While looking at the SSA of following code, i noticed that these rules do not work properly, and the types are loaded indirectly through an itab, instead of statically. type M interface{ M() } type A interface{ A() } type Impl struct{} func (*Impl) M() {} func (*Impl) A() {} func main() { var a M = &Impl{} a.(A).A() } Change-Id: Ia275993f81a2e7302102d4ff87ac28586023d13c GitHub-Last-Rev: 4bfc9019172929d0b0f1c8a1b7eb28cdbc9b87ef GitHub-Pull-Request: golang/go#71784 Reviewed-on: https://go-review.googlesource.com/c/go/+/649500 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'test/codegen')
-rw-r--r--test/codegen/load_type_from_itab.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/codegen/load_type_from_itab.go b/test/codegen/load_type_from_itab.go
new file mode 100644
index 0000000000..b47044fcbd
--- /dev/null
+++ b/test/codegen/load_type_from_itab.go
@@ -0,0 +1,24 @@
+// asmcheck
+
+// Copyright 2025 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.
+
+// This test makes sure that we statically load a type from an itab, instead
+// of doing a indirect load from thet itab.
+
+package codegen
+
+type M interface{ M() }
+type A interface{ A() }
+
+type Impl struct{}
+
+func (*Impl) M() {}
+func (*Impl) A() {}
+
+func main() {
+ var a M = &Impl{}
+ // amd64:`LEAQ\ttype:.*Impl`
+ a.(A).A()
+}