]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.unified] cmd/compile: fix missing method value wrapper in unified IR
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 23 May 2022 17:41:13 +0000 (00:41 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 6 Jun 2022 19:20:41 +0000 (19:20 +0000)
Unified IR uses to generate wrappers after the global inlining pass, so
it needs to apply inlining for the wrappers itself. However, inlining
may reveal new method value nodes which have not been seen yet, thus
unified IR never generates wrappers for them.

To fix it, just visiting the wrapper function body once more time after
inlining, and generate wrappers for any new method value nodes.

Fixes #52128

Change-Id: I78631c4faa0b00357d4f84704d3525fd38a52cd7
Reviewed-on: https://go-review.googlesource.com/c/go/+/410344
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/noder/reader.go
test/fixedbugs/issue52128.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue52128.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue52128.dir/p.go [new file with mode: 0644]
test/fixedbugs/issue52128.go [new file with mode: 0644]

index 0440d324ccf0e1f7f96e266dec2f98bc6c74059d..635f02630f73d8dff2f036cd919bf16b8588aea3 100644 (file)
@@ -2468,6 +2468,15 @@ func finishWrapperFunc(fn *ir.Func, target *ir.Package) {
        // so we're responsible for applying inlining ourselves here.
        inline.InlineCalls(fn)
 
+       // The body of wrapper function after inlining may reveal new ir.OMETHVALUE node,
+       // we don't know whether wrapper function has been generated for it or not, so
+       // generate one immediately here.
+       ir.VisitList(fn.Body, func(n ir.Node) {
+               if n, ok := n.(*ir.SelectorExpr); ok && n.Op() == ir.OMETHVALUE {
+                       wrapMethodValue(n.X.Type(), n.Selection, target, true)
+               }
+       })
+
        target.Decls = append(target.Decls, fn)
 }
 
diff --git a/test/fixedbugs/issue52128.dir/a.go b/test/fixedbugs/issue52128.dir/a.go
new file mode 100644 (file)
index 0000000..0abf831
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2022 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{}
+
+type F func()
+
+type s struct {
+       f F
+}
+
+func NewWithF(f F) *s {
+       return &s{f: f}
+}
+
+func NewWithFuncI(func() I) *s {
+       return &s{}
+}
diff --git a/test/fixedbugs/issue52128.dir/b.go b/test/fixedbugs/issue52128.dir/b.go
new file mode 100644 (file)
index 0000000..86f6ed7
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2022 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 b
+
+import (
+       "./a"
+)
+
+type S struct{}
+
+func (s *S) M1() a.I {
+       return a.NewWithF(s.M2)
+}
+
+func (s *S) M2() {}
diff --git a/test/fixedbugs/issue52128.dir/p.go b/test/fixedbugs/issue52128.dir/p.go
new file mode 100644 (file)
index 0000000..d3f3dbb
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2022 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 p
+
+import (
+       "./a"
+       "./b"
+)
+
+func f() {
+       a.NewWithFuncI((&b.S{}).M1)
+}
diff --git a/test/fixedbugs/issue52128.go b/test/fixedbugs/issue52128.go
new file mode 100644 (file)
index 0000000..8bb5c3e
--- /dev/null
@@ -0,0 +1,7 @@
+// compiledir
+
+// Copyright 2022 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 ignored