Skip to content

Commit 771b8ea

Browse files
committed
cmd/compile: fix missing markHiddenClosureDead in deadcode pass
CL 342350 fixed panic with dead hidden closures, by marking discarded hidden closure as dead, and won't compile them. However, the fix is incomplete. In case the "if" or "else" block end with panic or return statement: if true { return } # All nodes starts from here are dead the dead nodes must be processed with markHiddenClosureDead, but they are not, causing the compiler crashes. This CL adds that missing part. Fixes #48459 Change-Id: Ibdd10a61fc6459d139bbf4a66b0893b523ac6b67 Reviewed-on: https://go-review.googlesource.com/c/go/+/350695 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent c894b44 commit 771b8ea

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/cmd/compile/internal/deadcode/deadcode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func stmts(nn *ir.Nodes) {
117117
}
118118

119119
if cut {
120+
ir.VisitList((*nn)[i+1:len(*nn)], markHiddenClosureDead)
120121
*nn = (*nn)[:i+1]
121122
break
122123
}

test/fixedbugs/issue48459.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
func main() {
10+
if true {
11+
return
12+
}
13+
14+
defer func() {
15+
recover()
16+
}()
17+
}

0 commit comments

Comments
 (0)