1
0
mirror of https://github.com/golang/go synced 2024-11-14 13:30:30 -07:00
go/test/fixedbugs/issue46938.go
Cuong Manh Le de1c934b97 cmd/compile: fix checkptr false positive for (*[Big]T)(ptr)[:n:n] pattern
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>
2021-08-25 01:57:42 +00:00

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]
}