Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #12961 #13019

Merged
merged 1 commit into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -698,19 +698,21 @@ proc raiseExit(p: BProc) =
lineCg(p, cpsStmts, "if (NIM_UNLIKELY(*nimErr_)) goto LA$1_;$n",
[p.nestedTryStmts[^1].label])

proc finallyActions(p: BProc) =
if p.config.exc != excGoto and p.nestedTryStmts.len > 0 and p.nestedTryStmts[^1].inExcept:
# if the current try stmt have a finally block,
# we must execute it before reraising
let finallyBlock = p.nestedTryStmts[^1].fin
if finallyBlock != nil:
genSimpleBlock(p, finallyBlock[0])

proc genRaiseStmt(p: BProc, t: PNode) =
if p.config.exc != excGoto:
if p.config.exc == excCpp:
discard cgsym(p.module, "popCurrentExceptionEx")
if p.nestedTryStmts.len > 0 and p.nestedTryStmts[^1].inExcept:
# if the current try stmt have a finally block,
# we must execute it before reraising
let finallyBlock = p.nestedTryStmts[^1].fin
if finallyBlock != nil:
genSimpleBlock(p, finallyBlock[0])
if p.config.exc == excCpp:
discard cgsym(p.module, "popCurrentExceptionEx")
if t[0].kind != nkEmpty:
var a: TLoc
initLocExprSingleUse(p, t[0], a)
finallyActions(p)
var e = rdLoc(a)
var typ = skipTypes(t[0].typ, abstractPtrs)
genLineDir(p, t)
Expand All @@ -724,6 +726,7 @@ proc genRaiseStmt(p: BProc, t: PNode) =
if optOwnedRefs in p.config.globalOptions:
lineCg(p, cpsStmts, "$1 = NIM_NIL;$n", [e])
else:
finallyActions(p)
genLineDir(p, t)
# reraise the last exception:
if p.config.exc == excCpp:
Expand Down
11 changes: 11 additions & 0 deletions tests/destructor/tsetjmp_raise.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
discard """
outputsub: "index 2 not in 0 .. 0 [IndexError]"
exitcode: 1
cmd: "nim c --gc:arc --exceptions:setjmp $file"
"""

# bug #12961
# --gc:arc --exceptions:setjmp
let a = @[1]
echo a[2]