From: Russ Cox Date: Fri, 4 Dec 2020 04:56:16 +0000 (-0500) Subject: [dev.regabi] cmd/compile: avoid general traversal in deadcode X-Git-Tag: go1.17beta1~1539^2~371 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9ab3d854ad;p=gostls13.git [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 Run-TryBot: Russ Cox Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 65c5f2abce..2070297bc0 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -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