mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: check for iteration after range func loop exit
When this happens, panic. This is a revised version of a check that used #next, where this one instead uses a per-loop #exit flag, and catches more problematic iterators. Updates #56413. Updates #61405. Change-Id: I6574f754e475bb67b9236b4f6c25979089f9b629 Reviewed-on: https://go-review.googlesource.com/c/go/+/540263 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
6f5aba995f
commit
b5e31780b6
10 changed files with 1522 additions and 39 deletions
|
|
@ -296,6 +296,13 @@ func deferproc(fn func()) {
|
|||
// been set and must not be clobbered.
|
||||
}
|
||||
|
||||
var rangeExitError = error(errorString("range function continued iteration after exit"))
|
||||
|
||||
//go:noinline
|
||||
func panicrangeexit() {
|
||||
panic(rangeExitError)
|
||||
}
|
||||
|
||||
// deferrangefunc is called by functions that are about to
|
||||
// execute a range-over-function loop in which the loop body
|
||||
// may execute a defer statement. That defer needs to add to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue