Skip to content

Commit

Permalink
cmd/compile: remove unnecessary nil-check
Browse files Browse the repository at this point in the history
Removes unnecessary nil-check when referencing offset from an
address. Suggested by Keith Randall in golang#27180.

Updates golang#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>
  • Loading branch information
growler authored and randall77 committed Sep 4, 2018
1 parent 24e51bb commit 669fa8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ssa/nilcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/nilptr3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 669fa8f

Please sign in to comment.