[dev.regabi] cmd/compile: avoid general traversal in deadcode

deadcode is trying to walk the statements it can find,
but it can sweep in other nodes too. Stop doing that:
only walk known statements containing statements.

Otherwise, if we put panics in expression accessors that
shouldn't be used anymore, deadcode can trip them.

deadcode would be a good candidate to rewrite using
EditChildren, but that would certainly cause toolstash
changes, since deadcode is so ad-hoc about exactly
which parts of the function it looks at. For now just
remove the general traversal and leave as is.

Passes buildall w/ toolstash -cmp.

Change-Id: I06481eb87350905597600203c4fa724d55645b46
Reviewed-on: https://go-review.googlesource.com/c/go/+/275377
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Russ Cox 2020-12-03 23:56:16 -05:00
parent bb5aa2b664
commit 9ab3d854ad

View file

@ -3860,9 +3860,24 @@ func deadcodeslice(nn *ir.Nodes) {
}
deadcodeslice(n.PtrInit())
deadcodeslice(n.PtrBody())
deadcodeslice(n.PtrList())
deadcodeslice(n.PtrRlist())
switch n.Op() {
case ir.OBLOCK:
deadcodeslice(n.PtrList())
case ir.OCASE:
deadcodeslice(n.PtrBody())
case ir.OFOR:
deadcodeslice(n.PtrBody())
case ir.OIF:
deadcodeslice(n.PtrBody())
deadcodeslice(n.PtrRlist())
case ir.ORANGE:
deadcodeslice(n.PtrBody())
case ir.OSELECT:
deadcodeslice(n.PtrList())
case ir.OSWITCH:
deadcodeslice(n.PtrList())
}
if cut {
nn.Set(nn.Slice()[:i+1])
break