]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: print "internal compiler error" message for all compiler panics
authorDan Scales <danscales@google.com>
Wed, 5 Jan 2022 23:20:50 +0000 (15:20 -0800)
committerDan Scales <danscales@google.com>
Tue, 11 Jan 2022 17:13:50 +0000 (17:13 +0000)
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>
src/cmd/compile/internal/gc/main.go

index 96c6730803dad96eb38b3dc66f7961c6c46ff74b..4c4a724cdf9def00091bee079867df65ae8281bc 100644 (file)
@@ -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)