// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package runtime

import (
	
	
)

func unsafestring( unsafe.Pointer,  int) {
	if  < 0 {
		panicunsafestringlen()
	}

	if uintptr() > -uintptr() {
		if  == nil {
			panicunsafestringnilptr()
		}
		panicunsafestringlen()
	}
}

// Keep this code in sync with cmd/compile/internal/walk/builtin.go:walkUnsafeString
func unsafestring64( unsafe.Pointer,  int64) {
	 := int()
	if int64() !=  {
		panicunsafestringlen()
	}
	unsafestring(, )
}

func unsafestringcheckptr( unsafe.Pointer,  int64) {
	unsafestring64(, )

	// Check that underlying array doesn't straddle multiple heap objects.
	// unsafestring64 has already checked for overflow.
	if checkptrStraddles(, uintptr()) {
		throw("checkptr: unsafe.String result straddles multiple allocations")
	}
}

func panicunsafestringlen() {
	panic(errorString("unsafe.String: len out of range"))
}

func panicunsafestringnilptr() {
	panic(errorString("unsafe.String: ptr is nil and len is not zero"))
}

// Keep this code in sync with cmd/compile/internal/walk/builtin.go:walkUnsafeSlice
func unsafeslice( *_type,  unsafe.Pointer,  int) {
	if  < 0 {
		panicunsafeslicelen1(getcallerpc())
	}

	if .Size_ == 0 {
		if  == nil &&  > 0 {
			panicunsafeslicenilptr1(getcallerpc())
		}
	}

	,  := math.MulUintptr(.Size_, uintptr())
	if  ||  > -uintptr() {
		if  == nil {
			panicunsafeslicenilptr1(getcallerpc())
		}
		panicunsafeslicelen1(getcallerpc())
	}
}

// Keep this code in sync with cmd/compile/internal/walk/builtin.go:walkUnsafeSlice
func unsafeslice64( *_type,  unsafe.Pointer,  int64) {
	 := int()
	if int64() !=  {
		panicunsafeslicelen1(getcallerpc())
	}
	unsafeslice(, , )
}

func unsafeslicecheckptr( *_type,  unsafe.Pointer,  int64) {
	unsafeslice64(, , )

	// Check that underlying array doesn't straddle multiple heap objects.
	// unsafeslice64 has already checked for overflow.
	if checkptrStraddles(, uintptr()*.Size_) {
		throw("checkptr: unsafe.Slice result straddles multiple allocations")
	}
}

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( uintptr) {
	panicCheck1(, "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( uintptr) {
	panicCheck1(, "unsafe.Slice: ptr is nil and len is not zero")
	panic(errorString("unsafe.Slice: ptr is nil and len is not zero"))
}

//go:linkname reflect_unsafeslice reflect.unsafeslice
func reflect_unsafeslice( *_type,  unsafe.Pointer,  int) {
	unsafeslice(, , )
}