From 95dde3f0290b0df797770afc899ae977ed89833e Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 5 May 2021 09:23:52 +0700 Subject: [PATCH] cmd/compile: do not substitute OGOTO inside a closure when inlining The inlsubst already does the same thing for OLABEL, so we must do the same thing for OGOTO. Otherwise, new inlined OGOTO node will be associated with non-existed label. Fixes #45947 Change-Id: I40eef095f57fd3438c38a0b5d9751d5d7ebf759e Reviewed-on: https://go-review.googlesource.com/c/go/+/316931 Trust: Cuong Manh Le Trust: Dan Scales Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Dan Scales --- src/cmd/compile/internal/inline/inl.go | 4 ++++ test/fixedbugs/issue45947.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/fixedbugs/issue45947.go diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 339ea77509..e07bb3b324 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -1394,6 +1394,10 @@ func (subst *inlsubst) node(n ir.Node) ir.Node { return ir.NewBlockStmt(base.Pos, init) case ir.OGOTO: + if subst.newclofn != nil { + // Don't do special substitutions if inside a closure + break + } n := n.(*ir.BranchStmt) m := ir.Copy(n).(*ir.BranchStmt) m.SetPos(subst.updatedPos(m.Pos())) diff --git a/test/fixedbugs/issue45947.go b/test/fixedbugs/issue45947.go new file mode 100644 index 0000000000..4086449340 --- /dev/null +++ b/test/fixedbugs/issue45947.go @@ -0,0 +1,16 @@ +// compile + +// Copyright 2021 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. + +package p + +func f() { + _ = func() func() { + return func() { + l: + goto l + } + }() +}