compiler: special slice bounds check for 64-bit numbers

It is allowed to index with an int64 even on a 32-bit platform, so we
have to handle that case. But make sure the normal case isn't penalized
by using 32-bit numbers when possible.
This commit is contained in:
Ayke van Laethem
2018-10-20 18:26:10 +02:00
parent 239504d9f4
commit 0a06c6014d
2 changed files with 30 additions and 9 deletions
+7
View File
@@ -36,6 +36,13 @@ func sliceBoundsCheck(length lenType, low, high uint) {
}
}
// Check for bounds in *ssa.Slice. Supports 64-bit indexes.
func sliceBoundsCheckLong(length lenType, low, high uint64) {
if !(0 <= low && low <= high && high <= uint64(length)) {
runtimePanic("slice out of range")
}
}
// Check for bounds in *ssa.MakeSlice.
func sliceBoundsCheckMake(length, capacity uint) {
if !(0 <= length && length <= capacity) {