cmd/compile: fix panic with nested dead hidden closures

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 #51839

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>
This commit is contained in:
Cuong Manh Le 2022-03-21 18:49:37 +07:00
parent 627d6d6d55
commit 129a2fcf6c
2 changed files with 23 additions and 0 deletions

View File

@ -163,4 +163,5 @@ func markHiddenClosureDead(n ir.Node) {
if clo.Func.IsHiddenClosure() { if clo.Func.IsHiddenClosure() {
clo.Func.SetIsDeadcodeClosure(true) clo.Func.SetIsDeadcodeClosure(true)
} }
ir.VisitList(clo.Func.Body, markHiddenClosureDead)
} }

View File

@ -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()
}()
}()
}
}