From e61d1445ab2304e2d6e4711f8477061192d5942c Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Mon, 16 Aug 2021 02:15:28 +0700 Subject: 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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- test/fixedbugs/issue47712.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/fixedbugs/issue47712.go (limited to 'test') 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() + }() + } +} -- cgit v1.2.3-54-g00ecf