diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index a2fb00e132..137675aa20 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -574,13 +574,11 @@ func inlnode(n *Node, maxCost int32, inlMap map[*Node]bool) *Node { } switch n.Op { - // inhibit inlining of their argument case ODEFER, OGO: switch n.Left.Op { case OCALLFUNC, OCALLMETH: n.Left.SetNoInline(true) } - return n // TODO do them here (or earlier), // so escape analysis can avoid more heapmoves. diff --git a/test/inline.go b/test/inline.go index 9b75bc5065..470414f883 100644 --- a/test/inline.go +++ b/test/inline.go @@ -246,3 +246,20 @@ func ii() { // ERROR "can inline ii" f := getMeth(t1) // ERROR "inlining call to getMeth" "t1.meth does not escape" _ = f(3) } + +// Issue #42194 - make sure that functions evaluated in +// go and defer statements can be inlined. +func gd1(int) { + defer gd1(gd2()) // ERROR "inlining call to gd2" + defer gd3()() // ERROR "inlining call to gd3" + go gd1(gd2()) // ERROR "inlining call to gd2" + go gd3()() // ERROR "inlining call to gd3" +} + +func gd2() int { // ERROR "can inline gd2" + return 1 +} + +func gd3() func() { // ERROR "can inline gd3" + return ii +}