github.com/c12o16h1/go/src@v0.0.0-20200114212001-5a151c0f00ed/runtime/testdata/testprog/checkptr.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import "unsafe" 8 9 func init() { 10 register("CheckPtrAlignment", CheckPtrAlignment) 11 register("CheckPtrArithmetic", CheckPtrArithmetic) 12 register("CheckPtrSize", CheckPtrSize) 13 register("CheckPtrSmall", CheckPtrSmall) 14 } 15 16 func CheckPtrAlignment() { 17 var x [2]int64 18 p := unsafe.Pointer(&x[0]) 19 sink2 = (*int64)(unsafe.Pointer(uintptr(p) + 1)) 20 } 21 22 func CheckPtrArithmetic() { 23 var x int 24 i := uintptr(unsafe.Pointer(&x)) 25 sink2 = (*int)(unsafe.Pointer(i)) 26 } 27 28 func CheckPtrSize() { 29 p := new(int64) 30 sink2 = p 31 sink2 = (*[100]int64)(unsafe.Pointer(p)) 32 } 33 34 func CheckPtrSmall() { 35 sink2 = unsafe.Pointer(uintptr(1)) 36 }