aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-08-16 02:15:28 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-08-16 18:20:12 +0000
commite61d1445ab2304e2d6e4711f8477061192d5942c (patch)
treeb1611c1766230336a4b6180c676123f01a940fd0 /test
parent5c7a460a1c108e5bf7a99817b86ebded7ce81812 (diff)
downloadgo-e61d1445ab2304e2d6e4711f8477061192d5942c.tar.gz
go-e61d1445ab2304e2d6e4711f8477061192d5942c.zip
cmd/compile: fix panic with dead hidden closures
Currently, for hidden closures, we always push them to compile queue during typechecking. If the hidden closure is discarded from the outer function body during deadcode, any desugaring phase after deadcode won't be applied to the closure. Thus, some un-expected OPs are passed to downstream passes, which they can't handle, the compiler goes boom! To fix this, we keep track of discarded hidden closures during deadcode pass, and won't compile them then. Fixes #47712 Change-Id: I078717d5d1f4f2fa39cbaf610cfffbb042e70ceb Reviewed-on: https://go-review.googlesource.com/c/go/+/342350 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue47712.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/fixedbugs/issue47712.go b/test/fixedbugs/issue47712.go
new file mode 100644
index 0000000000..81a2681592
--- /dev/null
+++ b/test/fixedbugs/issue47712.go
@@ -0,0 +1,23 @@
+// 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() {
+ if false {
+ defer func() {
+ _ = recover()
+ }()
+ }
+}
+
+func g() {
+ for false {
+ defer func() {
+ _ = recover()
+ }()
+ }
+}