From 7160e3252991d9462ee3a155b5504c564a6cffe5 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 8 Mar 2022 14:59:32 -0800 Subject: [PATCH] cmd/compile: mark instantiated generic functions as DUPOK Unified IR wasn't marking instantiated generic functions as DUPOK, even though they can appear in multiple compilation units, which evidently interfered with cmd/link's dead code elimination logic. Manually confirmed to fix the issue, but non-trivial to test within $GOROOT/test currently, because it's only reproducible when cmd/compile is invoked with -p. @rsc is currently investigating updating test/run.go appropriately, after which I'll revisit writing a test case. Fixes #51519. Change-Id: I74a79ed0ca15b25b826e419714af5ceb6e567012 Reviewed-on: https://go-review.googlesource.com/c/go/+/390956 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/cmd/compile/internal/noder/reader.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 004630236d6..73e4ddbbedc 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -644,6 +644,10 @@ func (pr *pkgReader) objIdx(idx int, implicits, explicits []*types.Type) ir.Node name.Func = ir.NewFunc(r.pos()) name.Func.Nname = name + if r.hasTypeParams() { + name.Func.SetDupok(true) + } + rext.funcExt(name) return name @@ -790,6 +794,10 @@ func (r *reader) method(rext *reader) *types.Field { name.Func = ir.NewFunc(r.pos()) name.Func.Nname = name + if r.hasTypeParams() { + name.Func.SetDupok(true) + } + rext.funcExt(name) meth := types.NewField(name.Func.Pos(), sym, typ)