compiler, runtime: implement recoverable divide-by-zero panic

This gets the math/bits and go/constant package tests to pass.

Unfortunately, this also has a binary size impact of around 150-200
bytes in many cases. I'm a bit on the edge on whether this is worth it,
since it's mostly used for getting package tests to work. But at the
same time, having working package tests is very valuable.
This commit is contained in:
Ayke van Laethem
2025-02-25 13:07:21 +01:00
parent adc0cae960
commit 88d273da97
5 changed files with 52 additions and 11 deletions
+13
View File
@@ -30,6 +30,9 @@ func main() {
println("\n# defer panic")
deferPanic()
println("\n# runtime panics")
runtimePanicDivByZero(1, 0)
println("\n# runtime.Goexit")
runtimeGoexit()
}
@@ -114,6 +117,16 @@ func deferPanic() {
println("defer panic")
}
func runtimePanicDivByZero(a, b int) int {
defer func() {
if err := recover(); err != nil {
println("recovered:", err)
}
}()
return a / b
}
func runtimeGoexit() {
wg.Add(1)
go func() {