mirror of
https://github.com/golang/go
synced 2024-11-11 19:51:37 -07:00
cmd/compile: skip "_" function in reflectdata.MarkUsedIfaceMethod
CL 256798 added compiler ability to retain only used interface methods, by generating a mark relocation whenever an interface method is used. To do that, the compiler needs the current function linker object. However, for unnamed function "func _()", its linker object is nil, causes the compiler crashes for code in #45258. CL 283313 fixed the code in #45258 unintentionally, since when the compiler now does not walk unnamed functions anymore. This CL fixes the root issue, by making reflectdata.MarkUsedIfaceMethod skips unnamed functions, and also adding regression test. Fixes #45258 Change-Id: I4cbefb0a89d9928f70c00dc8a271cb61cd20a49c Reviewed-on: https://go-review.googlesource.com/c/go/+/311130 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: Keith Randall <khr@golang.org>
This commit is contained in:
parent
c914e6160d
commit
a72622d028
@ -1837,6 +1837,10 @@ func MarkTypeUsedInInterface(t *types.Type, from *obj.LSym) {
|
||||
// MarkUsedIfaceMethod marks that an interface method is used in the current
|
||||
// function. n is OCALLINTER node.
|
||||
func MarkUsedIfaceMethod(n *ir.CallExpr) {
|
||||
// skip unnamed functions (func _())
|
||||
if ir.CurFunc.LSym == nil {
|
||||
return
|
||||
}
|
||||
dot := n.X.(*ir.SelectorExpr)
|
||||
ityp := dot.X.Type()
|
||||
tsym := TypeLinksym(ityp)
|
||||
|
28
test/fixedbugs/issue45258.go
Normal file
28
test/fixedbugs/issue45258.go
Normal file
@ -0,0 +1,28 @@
|
||||
// compile
|
||||
|
||||
// Copyright 2021 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 main
|
||||
|
||||
type Fooer interface {
|
||||
Foo() Barer
|
||||
}
|
||||
|
||||
type Barer interface {
|
||||
Bar()
|
||||
}
|
||||
|
||||
type impl struct{}
|
||||
|
||||
func (r *impl) Foo() Barer {
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *impl) Bar() {}
|
||||
|
||||
func _() {
|
||||
var r Fooer = &impl{}
|
||||
r.Foo().Bar()
|
||||
}
|
Loading…
Reference in New Issue
Block a user