From 4be7af23f97fe8d1b4210acde6789cf621564ec6 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Thu, 14 Jan 2021 19:40:07 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: fix ICE during ir.Dump fmt.go:dumpNodeHeader uses reflection to call all "func() bool"-typed methods on Nodes during printing, but the OnStack method that I added in CL 283233 isn't meant to be called on non-variables. dumpNodeHeader does already guard against panics, as happen in some other accessors, but not against Fatalf, as I was using in OnStack. So simply change OnStack to use panic too. Thanks to drchase@ for the report. Change-Id: I0cfac84a96292193401a32fc5e7fd3c48773e008 Reviewed-on: https://go-review.googlesource.com/c/go/+/284074 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky Reviewed-by: David Chase TryBot-Result: Go Bot --- src/cmd/compile/internal/ir/name.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/ir/name.go b/src/cmd/compile/internal/ir/name.go index d19b0440e68..64de42382e8 100644 --- a/src/cmd/compile/internal/ir/name.go +++ b/src/cmd/compile/internal/ir/name.go @@ -286,18 +286,17 @@ func (n *Name) SetLibfuzzerExtraCounter(b bool) { n.flags.set(nameLibfuzzerExtra // OnStack reports whether variable n may reside on the stack. func (n *Name) OnStack() bool { - if n.Op() != ONAME || n.Class == PFUNC { - base.Fatalf("%v is not a variable", n) - } - switch n.Class { - case PPARAM, PPARAMOUT, PAUTO: - return n.Esc() != EscHeap - case PEXTERN, PAUTOHEAP: - return false - default: - base.FatalfAt(n.Pos(), "%v has unknown class %v", n, n.Class) - panic("unreachable") + if n.Op() == ONAME { + switch n.Class { + case PPARAM, PPARAMOUT, PAUTO: + return n.Esc() != EscHeap + case PEXTERN, PAUTOHEAP: + return false + } } + // Note: fmt.go:dumpNodeHeader calls all "func() bool"-typed + // methods, but it can only recover from panics, not Fatalf. + panic(fmt.Sprintf("%v: not a variable: %v", base.FmtPos(n.Pos()), n)) } // MarkReadonly indicates that n is an ONAME with readonly contents.