// 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()
+ panicunsafeslicelen1(getcallerpc())
}
if et.size == 0 {
if ptr == nil && len > 0 {
- panicunsafeslicenilptr()
+ panicunsafeslicenilptr1(getcallerpc())
}
}
mem, overflow := math.MulUintptr(et.size, uintptr(len))
if overflow || mem > -uintptr(ptr) {
if ptr == nil {
- panicunsafeslicenilptr()
+ panicunsafeslicenilptr1(getcallerpc())
}
- panicunsafeslicelen()
+ panicunsafeslicelen1(getcallerpc())
}
}
func unsafeslice64(et *_type, ptr unsafe.Pointer, len64 int64) {
len := int(len64)
if int64(len) != len64 {
- panicunsafeslicelen()
+ panicunsafeslicelen1(getcallerpc())
}
unsafeslice(et, ptr, len)
}
}
func panicunsafeslicelen() {
+ // This is called only from compiler-generated code, so we can get the
+ // source of the panic.
+ panicunsafeslicelen1(getcallerpc())
+}
+
+//go:yeswritebarrierrec
+func panicunsafeslicelen1(pc uintptr) {
+ panicCheck1(pc, "unsafe.Slice: len out of range")
panic(errorString("unsafe.Slice: len out of range"))
}
func panicunsafeslicenilptr() {
+ // This is called only from compiler-generated code, so we can get the
+ // source of the panic.
+ panicunsafeslicenilptr1(getcallerpc())
+}
+
+//go:yeswritebarrierrec
+func panicunsafeslicenilptr1(pc uintptr) {
+ panicCheck1(pc, "unsafe.Slice: ptr is nil and len is not zero")
panic(errorString("unsafe.Slice: ptr is nil and len is not zero"))
}