aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-08-20 11:38:54 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-08-25 01:57:42 +0000
commitde1c934b9709728b15cc821a055155ee13e1d0ab (patch)
treee755f419c10b85990e9336958d2aa2e4ae3ac326 /test
parent54cdef1f101a7a15fa6412fbedf8b009a1f725a1 (diff)
downloadgo-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.go29
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]
+}