mirror of
https://github.com/golang/go
synced 2024-11-23 07:00:05 -07:00
de1c934b97
The checkptr instrumentation is currently inserted before slice operation has validated that n <= Big. So instead of panic, checkptr have false positive throws. To fix this, just insert the checkptr instrumentation after the bound checking during SSA generation. Fixes #46938 Change-Id: I9dbf84441c711842ccc883f3654ca8766ac696d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/343972 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
30 lines
584 B
Go
30 lines
584 B
Go
// run -gcflags="-d=checkptr"
|
|
|
|
// Copyright 2021 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.
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"unsafe"
|
|
)
|
|
|
|
func main() {
|
|
defer func() {
|
|
err := recover()
|
|
if err == nil {
|
|
panic("expected panic")
|
|
}
|
|
if got := err.(error).Error(); !strings.Contains(got, "slice bounds out of range") {
|
|
panic("expected panic slice out of bound, got " + got)
|
|
}
|
|
}()
|
|
s := make([]int64, 100)
|
|
p := unsafe.Pointer(&s[0])
|
|
n := 1000
|
|
|
|
_ = (*[10]int64)(p)[:n:n]
|
|
}
|