]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: fix ICE during ir.Dump
authorMatthew Dempsky <mdempsky@google.com>
Fri, 15 Jan 2021 03:40:07 +0000 (19:40 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 15 Jan 2021 04:08:47 +0000 (04:08 +0000)
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 <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

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

index d19b0440e68083f68355af76d2283056ef8ef849..64de42382e80c1b7ff84b1631c4cc663d5887d6a 100644 (file)
@@ -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.