aboutsummaryrefslogtreecommitdiff
path: root/test/nilptr3.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2017-08-24 15:23:27 -0700
committerKeith Randall <khr@golang.org>2017-08-25 03:26:58 +0000
commitf1517ec6e5d1ccf04c1266e710545436b972750f (patch)
tree5ff6536a085b3969ec5be3736555cdcf15d8b692 /test/nilptr3.go
parente258249c247d7135f164f4f0b3abb29bebe75767 (diff)
downloadgo-f1517ec6e5d1ccf04c1266e710545436b972750f.tar.gz
go-f1517ec6e5d1ccf04c1266e710545436b972750f.zip
cmd/compile: remove more nil ptr checks after newobject
For code like the following (where x escapes): x := []int{1} We're currently generating a nil check. The line above is really 3 operations: t := new([1]int) t[0] = 1 x := t[:] We remove the nil check for t[0] = 1, but not for t[:]. Our current nil check removal rule is too strict about the possible memory arguments of the nil check. Unlike zeroing or storing to the result of runtime.newobject, the nilness of runtime.newobject is always false, even after other stores have happened in the meantime. Change-Id: I95fad4e3a59c27effdb37c43ea215e18f30b1e5f Reviewed-on: https://go-review.googlesource.com/58711 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/nilptr3.go')
-rw-r--r--test/nilptr3.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/nilptr3.go b/test/nilptr3.go
index 195c8ca043..9a96bb5386 100644
--- a/test/nilptr3.go
+++ b/test/nilptr3.go
@@ -259,3 +259,10 @@ func f7() (*Struct, float64) {
func f8(t *[8]int) [8]int {
return *t // ERROR "removed nil check"
}
+
+func f9() []int {
+ x := new([1]int)
+ x[0] = 1 // ERROR "removed nil check"
+ y := x[:] // ERROR "removed nil check"
+ return y
+}