aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorJonah Uellenberg <JonahUellenberg@gmail.com>2026-02-06 02:48:07 +0000
committerGopher Robot <gobot@golang.org>2026-02-06 09:40:28 -0800
commitbd7b8a52c847afcfc15b21741ec8972275a79c34 (patch)
tree53de07a77f8c0593f9213b238febe3e38a582f5f /src/runtime
parent5f51b092846ae43d03092d866449d9933a8bf42b (diff)
downloadgo-bd7b8a52c847afcfc15b21741ec8972275a79c34.tar.xz
runtime: add explicit lower bounds check to decoderune
decoderune is only called by generated code, so we can guarantee that it's non-negative. This allows eliminating the automatic bounds check in it. To make this work, we need to expand the existing optimization to uints. This generally enables BCE for cases like this: ```go func test(list []int, idx uint64) int { if idx >= uint64(len(list)) { return 0 } list1 := list[idx:] return list1[0] } ``` Change-Id: I86a51b26ca0e63522dec99f7d6efe6bdcd2d6487 GitHub-Last-Rev: 82d44e0a080b53ee02c31ee1f92a8a0acd8d2621 GitHub-Pull-Request: golang/go#76610 Reviewed-on: https://go-review.googlesource.com/c/go/+/725101 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/utf8.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/utf8.go b/src/runtime/utf8.go
index 52b757662d..e94b89ef3e 100644
--- a/src/runtime/utf8.go
+++ b/src/runtime/utf8.go
@@ -57,10 +57,10 @@ func countrunes(s string) int {
// If the string appears to be incomplete or decoding problems
// are encountered (runeerror, k + 1) is returned to ensure
// progress when decoderune is used to iterate over a string.
-func decoderune(s string, k int) (r rune, pos int) {
+func decoderune(s string, k uint) (r rune, pos uint) {
pos = k
- if k >= len(s) {
+ if k >= uint(len(s)) {
return runeError, k + 1
}