aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/panic.go
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2023-11-07 17:20:35 -0500
committerDavid Chase <drchase@google.com>2023-11-15 20:07:46 +0000
commitb5e31780b612c1317c9853f9e59df5c1bd0b3552 (patch)
treed4aeef07ecf100d1f74e0db11bceab57e2f6fe2d /src/runtime/panic.go
parent6f5aba995fdea76433337d1a8030518bdadfae28 (diff)
downloadgo-b5e31780b612c1317c9853f9e59df5c1bd0b3552.tar.xz
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>
Diffstat (limited to 'src/runtime/panic.go')
-rw-r--r--src/runtime/panic.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/runtime/panic.go b/src/runtime/panic.go
index 5f54ee4b01..36d658aa4c 100644
--- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -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