]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: set OpLoad argument type interface{} correctly
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 23 Nov 2020 17:58:00 +0000 (00:58 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 24 Nov 2020 03:06:15 +0000 (03:06 +0000)
CL 271906 allows loading single field of typed-interface{} OpIData, but
it does not update the corresponding selector type. So the generated
OpLoad has the named type instead, prevent it from being lowered by
lower pass.

Fixes #42784

Change-Id: Idf32e4f711731be09d508dd712b60bc8c58309bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/272466
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/ssa/expand_calls.go
test/fixedbugs/issue42784.go [new file with mode: 0644]

index 180afab33b1c72fe17a3c9b1e36d27a5b9ded5c4..f266e49327eee56a1bb9d4ce94ab3ca0d0beb3a2 100644 (file)
@@ -250,6 +250,9 @@ func expandCalls(f *Func) {
                        if leafType != selector.Type && !selector.Type.IsEmptyInterface() { // empty interface for #42727
                                f.Fatalf("Unexpected Load as selector, leaf=%s, selector=%s\n", leaf.LongString(), selector.LongString())
                        }
+                       if selector.Type.IsEmptyInterface() {
+                               selector.Type = typ.BytePtr
+                       }
                        leaf.copyOf(selector)
                        for _, s := range namedSelects[selector] {
                                locs = append(locs, f.Names[s.locIndex])
diff --git a/test/fixedbugs/issue42784.go b/test/fixedbugs/issue42784.go
new file mode 100644 (file)
index 0000000..e2b06e9
--- /dev/null
@@ -0,0 +1,26 @@
+// compile
+
+// 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.
+
+// Ensure that late expansion correctly set OpLoad argument type interface{}
+
+package p
+
+type iface interface {
+       m()
+}
+
+type it interface{}
+
+type makeIface func() iface
+
+func f() {
+       var im makeIface
+       e := im().(it)
+       g(e)
+}
+
+//go:noinline
+func g(i it) {}