3 // Copyright 2023 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
14 func shift[T any]() int64 {
15 return 1 << unsafe.Sizeof(*new(T))
18 func div[T any]() uintptr {
19 return 1 / unsafe.Sizeof(*new(T))
22 func add[T any]() int64 {
23 return 1<<63 - 1 + int64(unsafe.Sizeof(*new(T)))
34 shouldPanic("divide by zero", func() { div[[0]byte]() })
37 func shouldPanic(str string, f func()) {
41 panic("did not panic")
43 s := err.(error).Error()
44 if !strings.Contains(s, str) {
45 panic("got panic " + s + ", want " + str)