From 1b0a0316802b8048d69da49dc23c5a5ab08e8ae8 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 22 Apr 2021 20:36:05 -0400 Subject: [PATCH] cmd/compile: escape "go" wrapper closure everywhere For go statement, the wrapper closure needs to esacpe because it runs asynchronously. Currently, it is not allowed for closures to escape in the runtime. We have worked around this in the runtime, so it doesn't "go" any function with arguments and so doesn't need wrapping. If it ever does, it is not that we can have the closure not escape, which may lead to miscompilation. Instead, make the closure escape (which will fail the compilation). In the future we may allow go'd closure to escape in the runtime. Change-Id: I5bbe47b524371d2270c242f6c275013cd52abfc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/312889 Trust: Cherry Zhang Reviewed-by: Than McIntosh --- src/cmd/compile/internal/walk/order.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/walk/order.go b/src/cmd/compile/internal/walk/order.go index 7037b8ea602..99a166119a9 100644 --- a/src/cmd/compile/internal/walk/order.go +++ b/src/cmd/compile/internal/walk/order.go @@ -1582,10 +1582,8 @@ func (o *orderState) wrapGoDefer(n *ir.GoDeferStmt) { // (needs heap allocation). cloEscapes := func() bool { if n.Op() == ir.OGO { - // For "go", assume that all closures escape (with an - // exception for the runtime, which doesn't permit - // heap-allocated closures). - return base.Ctxt.Pkgpath != "runtime" + // For "go", assume that all closures escape. + return true } // For defer, just use whatever result escape analysis // has determined for the defer.