2022-03-18 11:46:15 -06:00
|
|
|
// run
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2022-08-31 21:32:20 -06:00
|
|
|
//go:build cgo && !aix
|
2022-08-07 11:14:43 -06:00
|
|
|
|
2022-03-18 11:46:15 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2022-08-07 11:14:43 -06:00
|
|
|
"runtime/cgo"
|
2022-03-18 11:46:15 -06:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2022-08-07 11:14:43 -06:00
|
|
|
type S struct{ _ cgo.Incomplete }
|
2022-03-18 11:46:15 -06:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
p := (*S)(unsafe.Pointer(uintptr(0x8000)))
|
|
|
|
var v any = p
|
|
|
|
p2 := v.(*S)
|
|
|
|
if p != p2 {
|
|
|
|
log.Fatalf("%p != %p", unsafe.Pointer(p), unsafe.Pointer(p2))
|
|
|
|
}
|
|
|
|
p2 = typeAssert[*S](v)
|
|
|
|
if p != p2 {
|
|
|
|
log.Fatalf("%p != %p from typeAssert", unsafe.Pointer(p), unsafe.Pointer(p2))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func typeAssert[T any](v any) T {
|
|
|
|
return v.(T)
|
|
|
|
}
|