]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: remove unnecessary nil-check
authorAlexey Naidonov <alexey.naidyonov@gmail.com>
Mon, 27 Aug 2018 21:39:34 +0000 (00:39 +0300)
committerKeith Randall <khr@golang.org>
Tue, 4 Sep 2018 17:44:14 +0000 (17:44 +0000)
Removes unnecessary nil-check when referencing offset from an
address. Suggested by Keith Randall in golang/go#27180.

Updates golang/go#27180

Change-Id: I326ed7fda7cfa98b7e4354c811900707fee26021
Reviewed-on: https://go-review.googlesource.com/131735
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/ssa/nilcheck.go
test/nilptr3.go

index 0359e25c9873526bd4e64b5568f07a1b2a10dfef..f2e17c606b50e718a8e30fd83f76836ff88997e2 100644 (file)
@@ -47,7 +47,7 @@ func nilcheckelim(f *Func) {
                        // a value resulting from taking the address of a
                        // value, or a value constructed from an offset of a
                        // non-nil ptr (OpAddPtr) implies it is non-nil
-                       if v.Op == OpAddr || v.Op == OpLocalAddr || v.Op == OpAddPtr {
+                       if v.Op == OpAddr || v.Op == OpLocalAddr || v.Op == OpAddPtr || v.Op == OpOffPtr {
                                nonNilValues[v.ID] = true
                        }
                }
index a22e60ef11f61ba2022e9d6c44be66870af8c73c..6aa718e027cda71991c76b338128487c3373b6d4 100644 (file)
@@ -246,8 +246,8 @@ type TT struct {
 
 func f(t *TT) *byte {
        // See issue 17242.
-       s := &t.SS  // ERROR "removed nil check"
-       return &s.x // ERROR "generated nil check"
+       s := &t.SS  // ERROR "generated nil check"
+       return &s.x // ERROR "removed nil check"
 }
 
 // make sure not to do nil check for newobject