From 02920c2cd932a28cca7f38e149844e55ca5c5f56 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 23 Apr 2019 21:51:38 +0200 Subject: [PATCH] fixes #11082 --- compiler/ccgstmts.nim | 8 +++++--- compiler/cgendata.nim | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 25bcdf65e..9d7f835ab 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -207,7 +207,7 @@ proc blockLeaveActions(p: BProc, howManyTrys, howManyExcepts: int) = let tryStmt = p.nestedTryStmts.pop if not p.module.compileToCpp or optNoCppExceptions in p.config.globalOptions: # Pop safe points generated by try - if not tryStmt.inExcept and not isDefined(p.config, "nimQuirky"): + if not tryStmt.inExcept: linefmt(p, cpsStmts, "#popSafePoint();$n", []) # Pop this try-stmt of the list of nested trys @@ -449,7 +449,7 @@ proc genReturnStmt(p: BProc, t: PNode) = blockLeaveActions(p, howManyTrys = p.nestedTryStmts.len, howManyExcepts = p.inExceptBlockLen) - if (p.finallySafePoints.len > 0) and not isDefined(p.config, "nimQuirky"): + if (p.finallySafePoints.len > 0) and not p.noSafePoints: # If we're in a finally block, and we came here by exception # consume it before we return. var safePoint = p.finallySafePoints[p.finallySafePoints.len-1] @@ -1004,6 +1004,8 @@ proc genTry(p: BProc, t: PNode, d: var TLoc) = (t.kind == nkHiddenTryStmt and sfSystemModule in p.module.module.flags) if not quirkyExceptions: p.module.includeHeader("") + else: + p.noSafePoints = true genLineDir(p, t) discard cgsym(p.module, "Exception") var safePoint: Rope @@ -1021,7 +1023,7 @@ proc genTry(p: BProc, t: PNode, d: var TLoc) = linefmt(p, cpsStmts, "$1.status = setjmp($1.context);$n", [safePoint]) startBlock(p, "if ($1.status == 0) {$n", [safePoint]) var length = sonsLen(t) - add(p.nestedTryStmts, (t, false)) + add(p.nestedTryStmts, (t, quirkyExceptions)) expr(p, t.sons[0], d) if not quirkyExceptions: linefmt(p, cpsStmts, "#popSafePoint();$n", []) diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index 4cd66b333..d9c3b7b86 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -70,6 +70,7 @@ type threadVarAccessed*: bool # true if the proc already accessed some threadvar hasCurFramePointer*: bool # true if _nimCurFrame var needed to recover after # exception is generated + noSafePoints*: bool # the proc doesn't use safe points in exception handling lastLineInfo*: TLineInfo # to avoid generating excessive 'nimln' statements currLineInfo*: TLineInfo # AST codegen will make this superfluous nestedTryStmts*: seq[tuple[n: PNode, inExcept: bool]]