From: Yongyue Sun Date: Thu, 15 May 2025 13:53:23 +0000 (+0000) Subject: cmd/compile: create LSym for closures with type conversion X-Git-Tag: go1.25rc1~258 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fc641e7fae1b09e25402bc73660d2deea51c2ad6;p=gostls13.git cmd/compile: create LSym for closures with type conversion Follow-up to #54959 with another failing case. The linker needs FuncInfo metadata for all inlined functions. CL 436240 explicitly creates LSym for direct closure calls to ensure we keep the FuncInfo metadata. However, CL 436240 won't work if the direct closure call is wrapped by a no-effect type conversion, even if that closure could be inlined. This commit should fix such case. Fixes #73716 Change-Id: Icda6024da54c8d933f87300e691334c080344695 GitHub-Last-Rev: e9aed02eb6ef343e4ed2d8a79f6426abf917ab0e GitHub-Pull-Request: golang/go#73718 Reviewed-on: https://go-review.googlesource.com/c/go/+/672855 Reviewed-by: David Chase Reviewed-by: Cuong Manh Le LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index e30de3d8c8..e3480c2463 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -1117,12 +1117,18 @@ func mkinlcall(callerfn *ir.Func, n *ir.CallExpr, fn *ir.Func, bigCaller, closur // Not a standard call. return } - if n.Fun.Op() != ir.OCLOSURE { - // Not a direct closure call. + + var nf = n.Fun + // Skips ir.OCONVNOPs, see issue #73716. + for nf.Op() == ir.OCONVNOP { + nf = nf.(*ir.ConvExpr).X + } + if nf.Op() != ir.OCLOSURE { + // Not a direct closure call or one with type conversion. return } - clo := n.Fun.(*ir.ClosureExpr) + clo := nf.(*ir.ClosureExpr) if !clo.Func.IsClosure() { // enqueueFunc will handle non closures anyways. return diff --git a/test/fixedbugs/issue73716.go b/test/fixedbugs/issue73716.go new file mode 100644 index 0000000000..4680b362c6 --- /dev/null +++ b/test/fixedbugs/issue73716.go @@ -0,0 +1,37 @@ +// build + +// Copyright 2025 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. + +// Issue 73716: cmd/compile: unnamed functions missing FuncInfo + +package main + +import "fmt" + +type EP func() +type F func(EP) EP + +func main() { + eps := []EP{ep1, ep2} + var h EP + + for _, ep := range eps { + h = F(func(e EP) EP { + return func() { + ep() + e() + } + })(h) + } + h() +} + +func ep1() { + fmt.Printf("ep1\n") +} + +func ep2() { + fmt.Printf("ep2\n") +}