aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/walk/expr.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/walk/expr.go')
-rw-r--r--src/cmd/compile/internal/walk/expr.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/walk/expr.go b/src/cmd/compile/internal/walk/expr.go
index d7a20206c8..7b65db5100 100644
--- a/src/cmd/compile/internal/walk/expr.go
+++ b/src/cmd/compile/internal/walk/expr.go
@@ -480,8 +480,12 @@ func walkAddString(n *ir.AddStringExpr, init *ir.Nodes) ir.Node {
// walkCall walks an OCALLFUNC, OCALLINTER, or OCALLMETH node.
func walkCall(n *ir.CallExpr, init *ir.Nodes) ir.Node {
- if n.Op() == ir.OCALLINTER {
+ if n.Op() == ir.OCALLINTER || n.Op() == ir.OCALLMETH {
+ // We expect both interface call reflect.Type.Method and concrete
+ // call reflect.(*rtype).Method.
usemethod(n)
+ }
+ if n.Op() == ir.OCALLINTER {
reflectdata.MarkUsedIfaceMethod(n)
}
@@ -899,6 +903,16 @@ func usemethod(n *ir.CallExpr) {
}
}
+ // Don't mark reflect.(*rtype).Method, etc. themselves in the reflect package.
+ // Those functions may be alive via the itab, which should not cause all methods
+ // alive. We only want to mark their callers.
+ if base.Ctxt.Pkgpath == "reflect" {
+ switch ir.CurFunc.Nname.Sym().Name { // TODO: is there a better way than hardcoding the names?
+ case "(*rtype).Method", "(*rtype).MethodByName", "(*interfaceType).Method", "(*interfaceType).MethodByName":
+ return
+ }
+ }
+
// Note: Don't rely on res0.Type.String() since its formatting depends on multiple factors
// (including global variables such as numImports - was issue #19028).
// Also need to check for reflect package itself (see Issue #38515).