]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: do not substitute OGOTO inside a closure when inlining
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 5 May 2021 02:23:52 +0000 (09:23 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 5 May 2021 18:03:32 +0000 (18:03 +0000)
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 <cuong.manhle.vn@gmail.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
src/cmd/compile/internal/inline/inl.go
test/fixedbugs/issue45947.go [new file with mode: 0644]

index 339ea77509ab379e6139b402aee5cf743cbf6afa..e07bb3b3242c9699e4de92529e476eb63fc4c3ef 100644 (file)
@@ -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 (file)
index 0000000..4086449
--- /dev/null
@@ -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
+               }
+       }()
+}