From 25d74f324dde687e1bbf486ef444a1f73f48f4eb Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 8 Aug 2022 12:31:33 -0700 Subject: [PATCH] cmd/compile/internal/inline: fix latent CalleeEffects issue ir.ClosureExpr implements ir.InitNode, so ir.InitExpr can prepend init statements to it. However, CalleeEffects wasn't aware of this and could cause the init statements to get dropped when inlining a call to a closure. This isn't an issue today, because we don't create closures with init statements. But I ran into this within unified IR. Easy and robust solution: just take advantage that ir.TakeInit can handle any node. Change-Id: Ica05fbf6a8c5be4b11927daf84491a1140da5431 Reviewed-on: https://go-review.googlesource.com/c/go/+/422196 Reviewed-by: Than McIntosh Run-TryBot: Matthew Dempsky TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/inline/inl.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 77848577c6..795486f7a2 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -827,18 +827,18 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlMap map[*ir.Func]b // CalleeEffects appends any side effects from evaluating callee to init. func CalleeEffects(init *ir.Nodes, callee ir.Node) { for { + init.Append(ir.TakeInit(callee)...) + switch callee.Op() { case ir.ONAME, ir.OCLOSURE, ir.OMETHEXPR: return // done case ir.OCONVNOP: conv := callee.(*ir.ConvExpr) - init.Append(ir.TakeInit(conv)...) callee = conv.X case ir.OINLCALL: ic := callee.(*ir.InlinedCallExpr) - init.Append(ir.TakeInit(ic)...) init.Append(ic.Body.Take()...) callee = ic.SingleResult() -- 2.50.0