1
0
mirror of https://github.com/golang/go synced 2024-11-17 23:34:52 -07:00
go/test/reflectmethod7.go
Cherry Zhang ed8079096f cmd/compile: mark concrete call of reflect.(*rtype).Method as REFLECTMETHOD
For functions that call reflect.Type.Method (or MethodByName), we
mark it as REFLECTMETHOD, which tells the linker that methods
can be retrieved via reflection and the linker keeps all exported
methods live. Currently, this marking expects exactly the
interface call reflect.Type.Method (or MethodByName). But now the
compiler can devirtualize that call to a concrete call
reflect.(*rtype).Method (or MethodByName), which is not handled
and causing the linker to discard methods too aggressively.
Handle the latter in this CL.

Fixes #44207.

Change-Id: Ia4060472dbff6ab6a83d2ca8e60a3e3f180ee832
Reviewed-on: https://go-review.googlesource.com/c/go/+/290950
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-02-10 22:44:54 +00:00

25 lines
417 B
Go

// run
// 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.
// See issue 44207.
package main
import "reflect"
type S int
func (s S) M() {}
func main() {
t := reflect.TypeOf(S(0))
fn, ok := reflect.PtrTo(t).MethodByName("M")
if !ok {
panic("FAIL")
}
fn.Func.Call([]reflect.Value{reflect.New(t)})
}