From 1abe9c1c73739786bb927342c4072e229affea8f Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Wed, 5 Jan 2022 15:20:50 -0800 Subject: [PATCH] cmd/compile: print "internal compiler error" message for all compiler panics Change hidePanic (now renamed handlePanic) to print out the "internal compiler error" message for all panics and runtime exceptions, similar to what we already do for the SSA backend in ssa.Compile(). Previously, hidePanic would not catch panics/exceptions unless it wanted to completely hide the panic because there had already been some compiler errors. Tested by manually inserting a seg fault in the compiler, and verifying that the seg fault is cause and "internal compiler error" message (with stack trace) is displayed proeprly. Updates #50423 Change-Id: Ibe846012e147fcdcc63ac147aae4bdfc47bf5a58 Reviewed-on: https://go-review.googlesource.com/c/go/+/376057 Trust: Dan Scales Run-TryBot: Dan Scales TryBot-Result: Gopher Robot Reviewed-by: Russ Cox --- src/cmd/compile/internal/gc/main.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 96c6730803..4c4a724cdf 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -35,18 +35,18 @@ import ( "sort" ) -func hidePanic() { - if base.Debug.Panic == 0 && base.Errors() > 0 { - // If we've already complained about things - // in the program, don't bother complaining - // about a panic too; let the user clean up - // the code and try again. - if err := recover(); err != nil { - if err == "-h" { - panic(err) - } - base.ErrorExit() +// handlePanic ensures that we print out an "internal compiler error" for any panic +// or runtime exception during front-end compiler processing (unless there have +// already been some compiler errors). It may also be invoked from the explicit panic in +// hcrash(), in which case, we pass the panic on through. +func handlePanic() { + if err := recover(); err != nil { + if err == "-h" { + // Force real panic now with -h option (hcrash) - the error + // information will have already been printed. + panic(err) } + base.Fatalf("panic: %v", err) } } @@ -56,7 +56,7 @@ func hidePanic() { func Main(archInit func(*ssagen.ArchInfo)) { base.Timer.Start("fe", "init") - defer hidePanic() + defer handlePanic() archInit(&ssagen.Arch) -- 2.50.0