Skip to content

Commit 4be7af2

Browse files
committed
[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 <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: David Chase <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 35b9c66 commit 4be7af2

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/cmd/compile/internal/ir/name.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,17 @@ func (n *Name) SetLibfuzzerExtraCounter(b bool) { n.flags.set(nameLibfuzzerExtra
286286

287287
// OnStack reports whether variable n may reside on the stack.
288288
func (n *Name) OnStack() bool {
289-
if n.Op() != ONAME || n.Class == PFUNC {
290-
base.Fatalf("%v is not a variable", n)
291-
}
292-
switch n.Class {
293-
case PPARAM, PPARAMOUT, PAUTO:
294-
return n.Esc() != EscHeap
295-
case PEXTERN, PAUTOHEAP:
296-
return false
297-
default:
298-
base.FatalfAt(n.Pos(), "%v has unknown class %v", n, n.Class)
299-
panic("unreachable")
289+
if n.Op() == ONAME {
290+
switch n.Class {
291+
case PPARAM, PPARAMOUT, PAUTO:
292+
return n.Esc() != EscHeap
293+
case PEXTERN, PAUTOHEAP:
294+
return false
295+
}
300296
}
297+
// Note: fmt.go:dumpNodeHeader calls all "func() bool"-typed
298+
// methods, but it can only recover from panics, not Fatalf.
299+
panic(fmt.Sprintf("%v: not a variable: %v", base.FmtPos(n.Pos()), n))
301300
}
302301

303302
// MarkReadonly indicates that n is an ONAME with readonly contents.

0 commit comments

Comments
 (0)