]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.14] cmd/compile: fix checkptr handling of &^
authorMatthew Dempsky <mdempsky@google.com>
Thu, 20 Aug 2020 04:39:12 +0000 (21:39 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 21 Aug 2020 23:45:28 +0000 (23:45 +0000)
commit24dbf3e136da73770300ef8f639e89bd372ed9c9
tree4cf7e5047af2975330ed12880fd3100ecbd661cc
parent1112871bf24cd4bd1144e1ee51e8a4cd538bdb9b
[release-branch.go1.14] 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 #40968.

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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/249838
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/walk.go
src/runtime/checkptr_test.go
src/runtime/testdata/testprog/checkptr.go
test/fixedbugs/issue40917.go [new file with mode: 0644]