]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.18] cmd/compile: fix panic with nested dead hidden closures
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 21 Mar 2022 11:49:37 +0000 (18:49 +0700)
committerCherry Mui <cherryyz@google.com>
Mon, 4 Apr 2022 19:55:44 +0000 (19:55 +0000)
CL 342350 fixed deadcode panic with dead hidden closures. However, a
closure may contains nested dead hidden closures, so we need to mark
them dead as well.

Fixes #51846

Change-Id: Ib54581adfc1bdea60e74d733cd30fd8e783da983
Reviewed-on: https://go-review.googlesource.com/c/go/+/394079
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/394080
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/deadcode/deadcode.go
test/fixedbugs/issue51839.go [new file with mode: 0644]

index 65a48b68032af3680baa5caf2f93d11305240ffb..c37a5a6990ced7fa656ba0868492621650955aa2 100644 (file)
@@ -163,4 +163,5 @@ func markHiddenClosureDead(n ir.Node) {
        if clo.Func.IsHiddenClosure() {
                clo.Func.SetIsDeadcodeClosure(true)
        }
+       ir.VisitList(clo.Func.Body, markHiddenClosureDead)
 }
diff --git a/test/fixedbugs/issue51839.go b/test/fixedbugs/issue51839.go
new file mode 100644 (file)
index 0000000..c3c1891
--- /dev/null
@@ -0,0 +1,22 @@
+// compile
+
+// Copyright 2022 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 main
+
+func main() {
+       testRecover()
+
+}
+
+func testRecover() {
+       if false {
+               func() {
+                       defer func() {
+                               _ = recover()
+                       }()
+               }()
+       }
+}