diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-08-20 11:38:54 +0700 |
---|---|---|
committer | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2021-08-25 01:57:42 +0000 |
commit | de1c934b9709728b15cc821a055155ee13e1d0ab (patch) | |
tree | e755f419c10b85990e9336958d2aa2e4ae3ac326 /test | |
parent | 54cdef1f101a7a15fa6412fbedf8b009a1f725a1 (diff) | |
download | go-de1c934b9709728b15cc821a055155ee13e1d0ab.tar.gz go-de1c934b9709728b15cc821a055155ee13e1d0ab.zip |
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/fixedbugs/issue46938.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/fixedbugs/issue46938.go b/test/fixedbugs/issue46938.go new file mode 100644 index 0000000000..87532d4769 --- /dev/null +++ b/test/fixedbugs/issue46938.go @@ -0,0 +1,29 @@ +// 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] +} |