]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: treat slice pointers as non-nil
authorKeith Randall <khr@google.com>
Mon, 25 Feb 2019 22:51:58 +0000 (14:51 -0800)
committerKeith Randall <khr@golang.org>
Tue, 26 Feb 2019 20:44:52 +0000 (20:44 +0000)
commit933e34ac995cf7b2a1d044dc530bfafbf697758d
tree2b5295efe187e7eb7a54bca61ade0141ae33daac
parent57976fe2b4cbd44d27e27af510494de0d182e703
cmd/compile: treat slice pointers as non-nil

var a []int = ...
p := &a[0]
_ = *p

We don't need to nil check on the 3rd line. If the bounds check on the 2nd
line passes, we know p is non-nil.

We rely on the fact that any cap>0 slice has a non-nil pointer as its
pointer to the backing array. This is true for all safely-constructed slices,
and I don't see any reason why someone would violate this rule using unsafe.

R=go1.13

Fixes #30366

Change-Id: I3ed764fcb72cfe1fbf963d8c1a82e24e3b6dead7
Reviewed-on: https://go-review.googlesource.com/c/163740
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/ssa/nilcheck.go
test/codegen/slices.go