Skip to content

Commit 1abe9c1

Browse files
committed
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 <[email protected]> Run-TryBot: Dan Scales <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 1cc3c73 commit 1abe9c1

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/cmd/compile/internal/gc/main.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ import (
3535
"sort"
3636
)
3737

38-
func hidePanic() {
39-
if base.Debug.Panic == 0 && base.Errors() > 0 {
40-
// If we've already complained about things
41-
// in the program, don't bother complaining
42-
// about a panic too; let the user clean up
43-
// the code and try again.
44-
if err := recover(); err != nil {
45-
if err == "-h" {
46-
panic(err)
47-
}
48-
base.ErrorExit()
38+
// handlePanic ensures that we print out an "internal compiler error" for any panic
39+
// or runtime exception during front-end compiler processing (unless there have
40+
// already been some compiler errors). It may also be invoked from the explicit panic in
41+
// hcrash(), in which case, we pass the panic on through.
42+
func handlePanic() {
43+
if err := recover(); err != nil {
44+
if err == "-h" {
45+
// Force real panic now with -h option (hcrash) - the error
46+
// information will have already been printed.
47+
panic(err)
4948
}
49+
base.Fatalf("panic: %v", err)
5050
}
5151
}
5252

@@ -56,7 +56,7 @@ func hidePanic() {
5656
func Main(archInit func(*ssagen.ArchInfo)) {
5757
base.Timer.Start("fe", "init")
5858

59-
defer hidePanic()
59+
defer handlePanic()
6060

6161
archInit(&ssagen.Arch)
6262

0 commit comments

Comments
 (0)