]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: recognize (*[Big]T)(ptr)[:n:m] pattern for -d=checkptr
authorMatthew Dempsky <mdempsky@google.com>
Thu, 17 Oct 2019 21:29:16 +0000 (14:29 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 21 Oct 2019 23:16:27 +0000 (23:16 +0000)
commit7b58581a232829f29a26d6ebee9f4c3ca59b4771
tree99d236ae49eb9a2bad764a75eccbd5972f613309
parentdba19c65a78c017e4f3fab94c8288bb120203078
cmd/compile: recognize (*[Big]T)(ptr)[:n:m] pattern for -d=checkptr

A common idiom for turning an unsafe.Pointer into a slice is to write:

    s := (*[Big]T)(ptr)[:n:m]

This technically violates Go's unsafe pointer rules (rule #1 says T2
can't be bigger than T1), but it's fairly common and not too difficult
to recognize, so might as well allow it for now so we can make
progress on #34972.

This should be revisited if #19367 is accepted.

Updates #22218.
Updates #34972.

Change-Id: Id824e2461904e770910b6e728b4234041d2cc8bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/201839
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/builtin.go
src/cmd/compile/internal/gc/builtin/runtime.go
src/cmd/compile/internal/gc/walk.go
src/runtime/checkptr.go