diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-03-10 00:52:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 00:52:46 +0100 |
commit | 090ba1e3a390e9997f45001e18dc93ba7aa091c3 (patch) | |
tree | aa21753396c77ebd4365797877da1f1767be7af8 | |
parent | 7d07897a9941717432d5872c3e0f203704902738 (diff) | |
download | Nim-090ba1e3a390e9997f45001e18dc93ba7aa091c3.tar.gz |
fixes #13436 (#13615)
-rw-r--r-- | compiler/cgen.nim | 12 | ||||
-rw-r--r-- | compiler/injectdestructors.nim | 3 | ||||
-rw-r--r-- | tests/destructor/tgotoexceptions6.nim | 10 |
3 files changed, 21 insertions, 4 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index fd14817e0..57424ec95 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1663,6 +1663,11 @@ proc genInitCode(m: BModule) = if beforeRetNeeded in m.initProc.flags: prc.add(~"\tBeforeRet_: ;$n") + + if sfMainModule in m.module.flags and m.config.exc == excGoto: + if getCompilerProc(m.g.graph, "nimTestErrorFlag") != nil: + m.appcg(prc, "\t#nimTestErrorFlag();$n", []) + if optStackTrace in m.initProc.options and preventStackTrace notin m.flags: prc.add(deinitFrame(m.initProc)) @@ -1990,9 +1995,10 @@ proc myClose(graph: ModuleGraph; b: PPassContext, n: PNode): PNode = if b == nil: return var m = BModule(b) if sfMainModule in m.module.flags: - let testForError = getCompilerProc(graph, "nimTestErrorFlag") - if testForError != nil and graph.config.exc == excGoto: - n.add newTree(nkCall, testForError.newSymNode) + # phase ordering problem here: We need to announce this + # dependency to 'nimTestErrorFlag' before system.c has been written to disk. + if m.config.exc == excGoto and getCompilerProc(graph, "nimTestErrorFlag") != nil: + discard cgsym(m, "nimTestErrorFlag") for i in countdown(high(graph.globalDestructors), 0): n.add graph.globalDestructors[i] diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 520ba46ce..161cb7652 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -591,7 +591,8 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode = # move the variable declaration to the top of the frame: c.addTopVar v # make sure it's destroyed at the end of the proc: - if not isUnpackedTuple(v): + if not isUnpackedTuple(v) and sfThread notin v.sym.flags: + # do not destroy thread vars for now at all for consistency. c.destroys.add genDestroy(c, v) elif c.inLoop > 0: # unpacked tuple needs reset at every loop iteration diff --git a/tests/destructor/tgotoexceptions6.nim b/tests/destructor/tgotoexceptions6.nim new file mode 100644 index 000000000..7c01f6a52 --- /dev/null +++ b/tests/destructor/tgotoexceptions6.nim @@ -0,0 +1,10 @@ +discard """ + cmd: "nim c --gc:arc --exceptions:goto $file" + outputsub: "Error: unhandled exception: virus detected [ValueError]" + exitcode: "1" +""" + +# bug #13436 +proc foo = + raise newException(ValueError, "virus detected") +foo() |