aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/slice.go
diff options
context:
space:
mode:
authorcuiweixie <cuiweixie@gmail.com>2022-08-16 17:52:13 +0800
committerMatthew Dempsky <mdempsky@google.com>2022-08-31 17:15:15 +0000
commitc7085329367e14f0aa828a3793cf66d9f82f05c2 (patch)
tree94f2e9ae0cfc74e1b3cd477480f718a2bd4b6814 /src/runtime/slice.go
parent301ca7513f427f6511fb67cc0385151403cd1729 (diff)
downloadgo-c7085329367e14f0aa828a3793cf66d9f82f05c2.tar.xz
cmd/compile: add support for unsafe.{String,StringData,SliceData}
For #53003 Change-Id: I13a761daca8b433b271a1feb711c103d9820772d Reviewed-on: https://go-review.googlesource.com/c/go/+/423774 Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: hopehook <hopehook@golangcn.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/slice.go')
-rw-r--r--src/runtime/slice.go48
1 files changed, 0 insertions, 48 deletions
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index e537f15826..0a203e4101 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -123,54 +123,6 @@ func mulUintptr(a, b uintptr) (uintptr, bool) {
return math.MulUintptr(a, b)
}
-// Keep this code in sync with cmd/compile/internal/walk/builtin.go:walkUnsafeSlice
-func unsafeslice(et *_type, ptr unsafe.Pointer, len int) {
- if len < 0 {
- panicunsafeslicelen()
- }
-
- if et.size == 0 {
- if ptr == nil && len > 0 {
- panicunsafeslicenilptr()
- }
- }
-
- mem, overflow := math.MulUintptr(et.size, uintptr(len))
- if overflow || mem > -uintptr(ptr) {
- if ptr == nil {
- panicunsafeslicenilptr()
- }
- panicunsafeslicelen()
- }
-}
-
-// Keep this code in sync with cmd/compile/internal/walk/builtin.go:walkUnsafeSlice
-func unsafeslice64(et *_type, ptr unsafe.Pointer, len64 int64) {
- len := int(len64)
- if int64(len) != len64 {
- panicunsafeslicelen()
- }
- unsafeslice(et, ptr, len)
-}
-
-func unsafeslicecheckptr(et *_type, ptr unsafe.Pointer, len64 int64) {
- unsafeslice64(et, ptr, len64)
-
- // Check that underlying array doesn't straddle multiple heap objects.
- // unsafeslice64 has already checked for overflow.
- if checkptrStraddles(ptr, uintptr(len64)*et.size) {
- throw("checkptr: unsafe.Slice result straddles multiple allocations")
- }
-}
-
-func panicunsafeslicelen() {
- panic(errorString("unsafe.Slice: len out of range"))
-}
-
-func panicunsafeslicenilptr() {
- panic(errorString("unsafe.Slice: ptr is nil and len is not zero"))
-}
-
// 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