From 669fa8f36a298cc0e2d1f817ca30c8d613ce7483 Mon Sep 17 00:00:00 2001 From: Alexey Naidonov Date: Tue, 28 Aug 2018 00:39:34 +0300 Subject: [PATCH] cmd/compile: remove unnecessary nil-check 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 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/nilcheck.go | 2 +- test/nilptr3.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/ssa/nilcheck.go b/src/cmd/compile/internal/ssa/nilcheck.go index 0359e25c98..f2e17c606b 100644 --- a/src/cmd/compile/internal/ssa/nilcheck.go +++ b/src/cmd/compile/internal/ssa/nilcheck.go @@ -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 } } diff --git a/test/nilptr3.go b/test/nilptr3.go index a22e60ef11..6aa718e027 100644 --- a/test/nilptr3.go +++ b/test/nilptr3.go @@ -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 -- 2.48.1