]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: avoid general traversal in deadcode
authorRuss Cox <rsc@golang.org>
Fri, 4 Dec 2020 04:56:16 +0000 (23:56 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 4 Dec 2020 16:52:56 +0000 (16:52 +0000)
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>
src/cmd/compile/internal/gc/typecheck.go

index 65c5f2abce0067a33bbca87a199194c764f802a2..2070297bc0da6e8e61dd3f47584ee48fd47e3515 100644 (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