aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-04-21 02:11:15 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-05-02 20:38:13 +0000
commitfadad851a3222867b374e901ede9c4919594837f (patch)
tree7b4efe046ea2da139b27ce5091d0cbd058bdf331 /src/runtime/slice.go
parent0d32d9e8a8784cf3ef39c471b73e502c51085b6d (diff)
downloadgo-fadad851a3222867b374e901ede9c4919594837f.tar.gz
go-fadad851a3222867b374e901ede9c4919594837f.zip
cmd/compile: implement unsafe.Add and unsafe.Slice
Updates #19367. Updates #40481. Change-Id: Iabd2afdd0d520e5d68fd9e6dedd013335a4b3886 Reviewed-on: https://go-review.googlesource.com/c/go/+/312214 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index c0647d95a0..f9d4154acf 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -112,6 +112,25 @@ func makeslice64(et *_type, len64, cap64 int64) unsafe.Pointer {
return makeslice(et, len, cap)
}
+func unsafeslice(et *_type, len int) {
+ mem, overflow := math.MulUintptr(et.size, uintptr(len))
+ if overflow || mem > maxAlloc || len < 0 {
+ panicunsafeslicelen()
+ }
+}
+
+func unsafeslice64(et *_type, len64 int64) {
+ len := int(len64)
+ if int64(len) != len64 {
+ panicunsafeslicelen()
+ }
+ unsafeslice(et, len)
+}
+
+func panicunsafeslicelen() {
+ panic(errorString("unsafe.Slice: len out of range"))
+}
+
// growslice handles slice growth during append.
// It is passed the slice element type, the old slice, and the desired new minimum capacity,
// and it returns a new slice with at least that capacity, with the old data