aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-08-19 21:39:12 -0700
committerDmitri Shuralyov <dmitshur@golang.org>2020-08-21 23:45:40 +0000
commitf454f70344703bd08e1f0a104fd2e6879e1d846c (patch)
treea55f5a0199576ff079fa16144a38f48a890054f4 /test
parentf2b710998902d6754d62810e1577c01313763342 (diff)
downloadgo-f454f70344703bd08e1f0a104fd2e6879e1d846c.tar.gz
go-f454f70344703bd08e1f0a104fd2e6879e1d846c.zip
[release-branch.go1.15] cmd/compile: fix checkptr handling of &^
checkptr has code to recognize &^ expressions, but it didn't take into account that "p &^ x" gets rewritten to "p & ^x" during walk, which resulted in false positive diagnostics. This CL changes walkexpr to mark OANDNOT expressions with Implicit when they're rewritten to OAND, so that walkCheckPtrArithmetic can still recognize them later. It would be slightly more idiomatic to instead mark the OBITNOT expression as Implicit (as it's a compiler-generated Node), but the OBITNOT expression might get constant folded. It's not worth the extra complexity/subtlety of relying on n.Right.Orig, so we set Implicit on the OAND node instead. To atone for this transgression, I add documentation for nodeImplicit. Updates #40917. Fixes #40934. Change-Id: I386304171ad299c530e151e5924f179e9a5fd5b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/249477 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> (cherry picked from commit e94544cf012535da6b3c9e735bc4026e2db1c99c) Reviewed-on: https://go-review.googlesource.com/c/go/+/249879 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue40917.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/fixedbugs/issue40917.go b/test/fixedbugs/issue40917.go
new file mode 100644
index 00000000000..2128be5eca4
--- /dev/null
+++ b/test/fixedbugs/issue40917.go
@@ -0,0 +1,23 @@
+// run -gcflags=-d=checkptr
+
+// 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 main() {
+ var x [2]uint64
+ a := unsafe.Pointer(&x[1])
+
+ b := a
+ b = unsafe.Pointer(uintptr(b) + 2)
+ b = unsafe.Pointer(uintptr(b) - 1)
+ b = unsafe.Pointer(uintptr(b) &^ 1)
+
+ if a != b {
+ panic("pointer arithmetic failed")
+ }
+}