From 9ab3d854ad95d06f5dd0874050ee57dd63c5a746 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 3 Dec 2020 23:56:16 -0500 Subject: [PATCH] [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 --- src/cmd/compile/internal/gc/typecheck.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 -- 2.50.0