aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/error.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2025-06-17 14:44:56 -0700
committerKeith Randall <khr@golang.org>2025-07-24 16:03:38 -0700
commit741a19ab4197fb528f8d7f7d8a73d3db3ef99355 (patch)
tree53992c6cf41f09265fd7118a5f0c8f55b92ab188 /src/runtime/error.go
parentce05ad448fe6ea3b9b33c0eab1143dcb40e3bbc3 (diff)
downloadgo-741a19ab4197fb528f8d7f7d8a73d3db3ef99355.tar.xz
runtime: move bounds check constants to internal/abi
For future use by the compiler. Change-Id: Id3da62006b283ac38008261c0ef88aaf71ef5896 Reviewed-on: https://go-review.googlesource.com/c/go/+/682456 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/error.go')
-rw-r--r--src/runtime/error.go54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/runtime/error.go b/src/runtime/error.go
index 8e50c0fea4..a2611bdfd9 100644
--- a/src/runtime/error.go
+++ b/src/runtime/error.go
@@ -132,52 +132,34 @@ type boundsError struct {
// Instead, we keep track of whether x should be interpreted as signed or unsigned.
// y is known to be nonnegative and to fit in an int.
signed bool
- code boundsErrorCode
+ code abi.BoundsErrorCode
}
-type boundsErrorCode uint8
-
-const (
- boundsIndex boundsErrorCode = iota // s[x], 0 <= x < len(s) failed
-
- boundsSliceAlen // s[?:x], 0 <= x <= len(s) failed
- boundsSliceAcap // s[?:x], 0 <= x <= cap(s) failed
- boundsSliceB // s[x:y], 0 <= x <= y failed (but boundsSliceA didn't happen)
-
- boundsSlice3Alen // s[?:?:x], 0 <= x <= len(s) failed
- boundsSlice3Acap // s[?:?:x], 0 <= x <= cap(s) failed
- boundsSlice3B // s[?:x:y], 0 <= x <= y failed (but boundsSlice3A didn't happen)
- boundsSlice3C // s[x:y:?], 0 <= x <= y failed (but boundsSlice3A/B didn't happen)
-
- boundsConvert // (*[x]T)(s), 0 <= x <= len(s) failed
- // Note: in the above, len(s) and cap(s) are stored in y
-)
-
// boundsErrorFmts provide error text for various out-of-bounds panics.
// Note: if you change these strings, you should adjust the size of the buffer
// in boundsError.Error below as well.
var boundsErrorFmts = [...]string{
- boundsIndex: "index out of range [%x] with length %y",
- boundsSliceAlen: "slice bounds out of range [:%x] with length %y",
- boundsSliceAcap: "slice bounds out of range [:%x] with capacity %y",
- boundsSliceB: "slice bounds out of range [%x:%y]",
- boundsSlice3Alen: "slice bounds out of range [::%x] with length %y",
- boundsSlice3Acap: "slice bounds out of range [::%x] with capacity %y",
- boundsSlice3B: "slice bounds out of range [:%x:%y]",
- boundsSlice3C: "slice bounds out of range [%x:%y:]",
- boundsConvert: "cannot convert slice with length %y to array or pointer to array with length %x",
+ abi.BoundsIndex: "index out of range [%x] with length %y",
+ abi.BoundsSliceAlen: "slice bounds out of range [:%x] with length %y",
+ abi.BoundsSliceAcap: "slice bounds out of range [:%x] with capacity %y",
+ abi.BoundsSliceB: "slice bounds out of range [%x:%y]",
+ abi.BoundsSlice3Alen: "slice bounds out of range [::%x] with length %y",
+ abi.BoundsSlice3Acap: "slice bounds out of range [::%x] with capacity %y",
+ abi.BoundsSlice3B: "slice bounds out of range [:%x:%y]",
+ abi.BoundsSlice3C: "slice bounds out of range [%x:%y:]",
+ abi.BoundsConvert: "cannot convert slice with length %y to array or pointer to array with length %x",
}
// boundsNegErrorFmts are overriding formats if x is negative. In this case there's no need to report y.
var boundsNegErrorFmts = [...]string{
- boundsIndex: "index out of range [%x]",
- boundsSliceAlen: "slice bounds out of range [:%x]",
- boundsSliceAcap: "slice bounds out of range [:%x]",
- boundsSliceB: "slice bounds out of range [%x:]",
- boundsSlice3Alen: "slice bounds out of range [::%x]",
- boundsSlice3Acap: "slice bounds out of range [::%x]",
- boundsSlice3B: "slice bounds out of range [:%x:]",
- boundsSlice3C: "slice bounds out of range [%x::]",
+ abi.BoundsIndex: "index out of range [%x]",
+ abi.BoundsSliceAlen: "slice bounds out of range [:%x]",
+ abi.BoundsSliceAcap: "slice bounds out of range [:%x]",
+ abi.BoundsSliceB: "slice bounds out of range [%x:]",
+ abi.BoundsSlice3Alen: "slice bounds out of range [::%x]",
+ abi.BoundsSlice3Acap: "slice bounds out of range [::%x]",
+ abi.BoundsSlice3B: "slice bounds out of range [:%x:]",
+ abi.BoundsSlice3C: "slice bounds out of range [%x::]",
}
func (e boundsError) RuntimeError() {}