mirror of
https://github.com/golang/go
synced 2024-10-02 22:25:08 +00:00
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 <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
24e51bbe64
commit
669fa8f36a
|
@ -47,7 +47,7 @@ func nilcheckelim(f *Func) {
|
||||||
// a value resulting from taking the address of a
|
// a value resulting from taking the address of a
|
||||||
// value, or a value constructed from an offset of a
|
// value, or a value constructed from an offset of a
|
||||||
// non-nil ptr (OpAddPtr) implies it is non-nil
|
// 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
|
nonNilValues[v.ID] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,8 +246,8 @@ type TT struct {
|
||||||
|
|
||||||
func f(t *TT) *byte {
|
func f(t *TT) *byte {
|
||||||
// See issue 17242.
|
// See issue 17242.
|
||||||
s := &t.SS // ERROR "removed nil check"
|
s := &t.SS // ERROR "generated nil check"
|
||||||
return &s.x // ERROR "generated nil check"
|
return &s.x // ERROR "removed nil check"
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure not to do nil check for newobject
|
// make sure not to do nil check for newobject
|
||||||
|
|
Loading…
Reference in a new issue