This commit is contained in:
Araq 2019-06-26 15:33:26 +02:00
commit 0a81b038fd
2 changed files with 31 additions and 12 deletions

View file

@ -806,17 +806,23 @@ proc p(n: PNode; c: var Con): PNode =
result[1][0] = p(result[1][0], c) result[1][0] = p(result[1][0], c)
of nkRaiseStmt: of nkRaiseStmt:
if optNimV2 in c.graph.config.globalOptions and n[0].kind != nkEmpty: if optNimV2 in c.graph.config.globalOptions and n[0].kind != nkEmpty:
let t = n[0].typ if n[0].kind in nkCallKinds:
let tmp = getTemp(c, t, n.info) let call = copyNode(n[0])
var m = genCopyNoCheck(c, t, tmp, n[0]) recurse(n[0], call)
result = copyNode(n)
result.add call
else:
let t = n[0].typ
let tmp = getTemp(c, t, n.info)
var m = genCopyNoCheck(c, t, tmp, n[0])
m.add p(n[0], c) m.add p(n[0], c)
result = newTree(nkStmtList, genWasMoved(tmp, c), m) result = newTree(nkStmtList, genWasMoved(tmp, c), m)
var toDisarm = n[0] var toDisarm = n[0]
if toDisarm.kind == nkStmtListExpr: toDisarm = toDisarm.lastSon if toDisarm.kind == nkStmtListExpr: toDisarm = toDisarm.lastSon
if toDisarm.kind == nkSym and toDisarm.sym.owner == c.owner: if toDisarm.kind == nkSym and toDisarm.sym.owner == c.owner:
result.add genWasMoved(toDisarm, c) result.add genWasMoved(toDisarm, c)
result.add newTree(nkRaiseStmt, tmp) result.add newTree(nkRaiseStmt, tmp)
else: else:
result = copyNode(n) result = copyNode(n)
recurse(n, result) recurse(n, result)

View file

@ -1,7 +1,7 @@
discard """ discard """
cmd: '''nim c --newruntime $file''' cmd: '''nim c --newruntime $file'''
output: '''OK 2 output: '''OK 3
4 1''' 5 1'''
""" """
import strutils, math import strutils, math
@ -36,6 +36,19 @@ except ValueError:
except: except:
discard discard
# bug #11577
proc newError*: owned(ref Exception) {.noinline.} =
new(result)
proc mainC =
raise newError()
try:
mainC()
except:
inc ok
echo "OK ", ok echo "OK ", ok
let (a, d) = allocCounters() let (a, d) = allocCounters()