diff options
author | Dan Scales <danscales@google.com> | 2022-01-05 15:20:50 -0800 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2022-01-11 17:13:50 +0000 |
commit | 1abe9c1c73739786bb927342c4072e229affea8f (patch) | |
tree | 7b93ecb2862ae322ebf0c437d117e92d2faaf849 /src | |
parent | 1cc3c735802f93eaf74b21795b8027163318ace1 (diff) | |
download | go-1abe9c1c73739786bb927342c4072e229affea8f.tar.gz go-1abe9c1c73739786bb927342c4072e229affea8f.zip |
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 <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 24 |
1 files 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) |