1// run -gcflags="-d=checkptr"
2
3// Copyright 2021 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
7package main
8
9import (
10	"strings"
11	"unsafe"
12)
13
14func main() {
15	defer func() {
16		err := recover()
17		if err == nil {
18			panic("expected panic")
19		}
20		if got := err.(error).Error(); !strings.Contains(got, "slice bounds out of range") {
21			panic("expected panic slice out of bound, got " + got)
22		}
23	}()
24	s := make([]int64, 100)
25	p := unsafe.Pointer(&s[0])
26	n := 1000
27
28	_ = (*[10]int64)(p)[:n:n]
29}
30