Skip to content

Commit fc641e7

Browse files
Abioydr2chase
authored andcommitted
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: e9aed02 GitHub-Pull-Request: #73718 Reviewed-on: https://go-review.googlesource.com/c/go/+/672855 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
1 parent 6df855e commit fc641e7

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/cmd/compile/internal/inline/inl.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,18 @@ func mkinlcall(callerfn *ir.Func, n *ir.CallExpr, fn *ir.Func, bigCaller, closur
11171117
// Not a standard call.
11181118
return
11191119
}
1120-
if n.Fun.Op() != ir.OCLOSURE {
1121-
// Not a direct closure call.
1120+
1121+
var nf = n.Fun
1122+
// Skips ir.OCONVNOPs, see issue #73716.
1123+
for nf.Op() == ir.OCONVNOP {
1124+
nf = nf.(*ir.ConvExpr).X
1125+
}
1126+
if nf.Op() != ir.OCLOSURE {
1127+
// Not a direct closure call or one with type conversion.
11221128
return
11231129
}
11241130

1125-
clo := n.Fun.(*ir.ClosureExpr)
1131+
clo := nf.(*ir.ClosureExpr)
11261132
if !clo.Func.IsClosure() {
11271133
// enqueueFunc will handle non closures anyways.
11281134
return

test/fixedbugs/issue73716.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// build
2+
3+
// Copyright 2025 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 73716: cmd/compile: unnamed functions missing FuncInfo
8+
9+
package main
10+
11+
import "fmt"
12+
13+
type EP func()
14+
type F func(EP) EP
15+
16+
func main() {
17+
eps := []EP{ep1, ep2}
18+
var h EP
19+
20+
for _, ep := range eps {
21+
h = F(func(e EP) EP {
22+
return func() {
23+
ep()
24+
e()
25+
}
26+
})(h)
27+
}
28+
h()
29+
}
30+
31+
func ep1() {
32+
fmt.Printf("ep1\n")
33+
}
34+
35+
func ep2() {
36+
fmt.Printf("ep2\n")
37+
}

0 commit comments

Comments
 (0)