diff options
author | Keith Randall <khr@golang.org> | 2023-03-24 14:31:29 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-03-29 21:55:11 +0000 |
commit | 0d9eb8bea26a1fbebc149aa1811e5c0d9201dc40 (patch) | |
tree | 30d5ad40b1fd4aab4187db9bd0c556b9402d55ce /test/nilptr3.go | |
parent | 9c75c4b6d75a1ee76f261f4fa7f3790efdbd51e4 (diff) | |
download | go-0d9eb8bea26a1fbebc149aa1811e5c0d9201dc40.tar.gz go-0d9eb8bea26a1fbebc149aa1811e5c0d9201dc40.zip |
cmd/compile: casts from slices to array pointers are known to be non-nil
The cast is proceeded by a bounds check. If the bounds check passes
then we know the pointer in the slice is non-nil.
... except casts to pointers of 0-sized arrays. They are strange, as
the bounds check can pass for a nil input.
Change-Id: Ic01cf4a82d59fbe3071d4b271c94efca9cafaec1
Reviewed-on: https://go-review.googlesource.com/c/go/+/479335
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Keith Randall <khr@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/nilptr3.go')
-rw-r--r-- | test/nilptr3.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/nilptr3.go b/test/nilptr3.go index 0e818ebf66..5f08a5b20c 100644 --- a/test/nilptr3.go +++ b/test/nilptr3.go @@ -248,3 +248,10 @@ func f10(p **int) int { /* */ *p // ERROR "removed nil check" } + +func f11(x []byte) { + p := (*[0]byte)(x) + _ = *p // ERROR "generated nil check" + q := (*[4]byte)(x) + _ = *q // ERROR "removed nil check" +} |