aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testprog/checkptr.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-01-09 15:26:01 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-01-10 21:40:21 +0000
commit5d0075156a01a8c9973188dc06b78aadabeb69da (patch)
tree9da2c7463365bf8e912760d181c9e421367e19f0 /src/runtime/testdata/testprog/checkptr.go
parentae0b735369317197773920ee282c68a01effaad3 (diff)
downloadgo-5d0075156a01a8c9973188dc06b78aadabeb69da.tar.gz
go-5d0075156a01a8c9973188dc06b78aadabeb69da.zip
runtime: add tests for checkptr
We had a few test cases to make sure checkptr didn't have certain false positives, but none to test for any true positives. This CL fixes that. Updates #22218. Change-Id: I24c02e469a4af43b1748829a9df325ce510f7cc4 Reviewed-on: https://go-review.googlesource.com/c/go/+/214238 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/testdata/testprog/checkptr.go')
-rw-r--r--src/runtime/testdata/testprog/checkptr.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/runtime/testdata/testprog/checkptr.go b/src/runtime/testdata/testprog/checkptr.go
new file mode 100644
index 0000000000..177db38e5a
--- /dev/null
+++ b/src/runtime/testdata/testprog/checkptr.go
@@ -0,0 +1,36 @@
+// Copyright 2020 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 "unsafe"
+
+func init() {
+ register("CheckPtrAlignment", CheckPtrAlignment)
+ register("CheckPtrArithmetic", CheckPtrArithmetic)
+ register("CheckPtrSize", CheckPtrSize)
+ register("CheckPtrSmall", CheckPtrSmall)
+}
+
+func CheckPtrAlignment() {
+ var x [2]int64
+ p := unsafe.Pointer(&x[0])
+ sink2 = (*int64)(unsafe.Pointer(uintptr(p) + 1))
+}
+
+func CheckPtrArithmetic() {
+ var x int
+ i := uintptr(unsafe.Pointer(&x))
+ sink2 = (*int)(unsafe.Pointer(i))
+}
+
+func CheckPtrSize() {
+ p := new(int64)
+ sink2 = p
+ sink2 = (*[100]int64)(unsafe.Pointer(p))
+}
+
+func CheckPtrSmall() {
+ sink2 = unsafe.Pointer(uintptr(1))
+}