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>
}
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