From 822c7acd3cafc2a3713ff7b6f5c3b1ac02252d68 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 4 Jan 2021 19:44:50 +0100 Subject: [PATCH] make --gc:arc --exceptions:quirky work again [backport:1.4] (#16583) * make --gc:arc --exceptions:quirky work again [backport:1.4] * fixes #16404 [backport:1.4] (cherry picked from commit 6317e4004dded87d698b41274e31d318fe52e877) --- compiler/commands.nim | 4 ++++ compiler/main.nim | 2 -- lib/system/embedded.nim | 10 ++++++++++ tests/manyloc/standalone/panicoverride.nim | 5 ----- tests/manyloc/standalone2/panicoverride.nim | 14 ++++++++++++++ tests/manyloc/standalone2/tavr.nim | 7 +++++++ tests/manyloc/standalone2/tavr.nim.cfg | 4 ++++ 7 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 tests/manyloc/standalone2/panicoverride.nim create mode 100644 tests/manyloc/standalone2/tavr.nim create mode 100644 tests/manyloc/standalone2/tavr.nim.cfg diff --git a/compiler/commands.nim b/compiler/commands.nim index e6080689cf..fa981133fe 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -513,6 +513,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; if pass in {passCmd2, passPP}: defineSymbol(conf.symbols, "nimSeqsV2") defineSymbol(conf.symbols, "nimV2") + if conf.exc == excNone and conf.backend != backendCpp: + conf.exc = excGoto of "orc": conf.selectedGC = gcOrc defineSymbol(conf.symbols, "gcdestructors") @@ -522,6 +524,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; if pass in {passCmd2, passPP}: defineSymbol(conf.symbols, "nimSeqsV2") defineSymbol(conf.symbols, "nimV2") + if conf.exc == excNone and conf.backend != backendCpp: + conf.exc = excGoto of "hooks": conf.selectedGC = gcHooks defineSymbol(conf.symbols, "gchooks") diff --git a/compiler/main.nim b/compiler/main.nim index c4feffeabe..fc37407847 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -197,8 +197,6 @@ proc mainCommand*(graph: ModuleGraph) = # A better solution might be to fix system.nim undefSymbol(conf.symbols, "useNimRtl") of backendInvalid: doAssert false - if conf.selectedGC in {gcArc, gcOrc} and conf.backend != backendCpp: - conf.exc = excGoto var commandAlreadyProcessed = false diff --git a/lib/system/embedded.nim b/lib/system/embedded.nim index c4f15a3360..258558c3f6 100644 --- a/lib/system/embedded.nim +++ b/lib/system/embedded.nim @@ -44,3 +44,13 @@ proc setControlCHook(hook: proc () {.noconv.}) = discard proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} = sysFatal(ReraiseDefect, "exception handling is not available") + +when gotoBasedExceptions: + var nimInErrorMode {.threadvar.}: bool + + proc nimErrorFlag(): ptr bool {.compilerRtl, inl.} = + result = addr(nimInErrorMode) + + proc nimTestErrorFlag() {.compilerRtl.} = + if nimInErrorMode: + sysFatal(ReraiseDefect, "exception handling is not available") diff --git a/tests/manyloc/standalone/panicoverride.nim b/tests/manyloc/standalone/panicoverride.nim index d9b3f43886..c0b8bb030e 100644 --- a/tests/manyloc/standalone/panicoverride.nim +++ b/tests/manyloc/standalone/panicoverride.nim @@ -11,9 +11,4 @@ proc panic(s: string) {.noreturn.} = rawoutput(s) exit(1) -# Alternatively we also could implement these 2 here: -# -# proc sysFatal(exceptn: typeDesc, message: string) {.noReturn.} -# proc sysFatal(exceptn: typeDesc, message, arg: string) {.noReturn.} - {.pop.} diff --git a/tests/manyloc/standalone2/panicoverride.nim b/tests/manyloc/standalone2/panicoverride.nim new file mode 100644 index 0000000000..c0b8bb030e --- /dev/null +++ b/tests/manyloc/standalone2/panicoverride.nim @@ -0,0 +1,14 @@ + +proc printf(frmt: cstring) {.varargs, importc, header: "", cdecl.} +proc exit(code: int) {.importc, header: "", cdecl.} + +{.push stack_trace: off, profiler:off.} + +proc rawoutput(s: string) = + printf("%s\n", s) + +proc panic(s: string) {.noreturn.} = + rawoutput(s) + exit(1) + +{.pop.} diff --git a/tests/manyloc/standalone2/tavr.nim b/tests/manyloc/standalone2/tavr.nim new file mode 100644 index 0000000000..6cbc5c6990 --- /dev/null +++ b/tests/manyloc/standalone2/tavr.nim @@ -0,0 +1,7 @@ +# bug #16404 + +proc printf(frmt: cstring) {.varargs, header: "", cdecl.} + +var x = 0 +inc x +printf("hi %ld\n", x+4777) diff --git a/tests/manyloc/standalone2/tavr.nim.cfg b/tests/manyloc/standalone2/tavr.nim.cfg new file mode 100644 index 0000000000..e5291969dd --- /dev/null +++ b/tests/manyloc/standalone2/tavr.nim.cfg @@ -0,0 +1,4 @@ +--gc:arc +--cpu:avr +--os:standalone +--compileOnly