test/fixedbugs/issue35027.go
raw| 1 | // run -gcflags=-d=checkptr |
| 2 | |
| 3 | // Copyright 2019 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. |
| 6 | |
| 7 | package main |
| 8 | |
| 9 | import ( |
| 10 | "reflect" |
| 11 | "unsafe" |
| 12 | ) |
| 13 | |
| 14 | var s []int |
| 15 | |
| 16 | func main() { |
| 17 | s = []int{42} |
| 18 | h := (*reflect.SliceHeader)(unsafe.Pointer(&s)) |
| 19 | x := *(*int)(unsafe.Pointer(h.Data)) |
| 20 | if x != 42 { |
| 21 | panic(x) |
| 22 | } |
| 23 | } |