fixes #10886 [backport] (#10897)

This commit is contained in:
Andreas Rumpf 2019-03-23 14:44:53 +01:00 • committed by GitHub
commit 0b2a3f6f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 7 deletions

View file

@ -388,16 +388,28 @@ proc genIf(c: PCtx, n: PNode; dest: var TDest) =
for endPos in endings: c.patch(endPos)
c.clearDest(n, dest)
proc isTemp(c: PCtx; dest: TDest): bool =
result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown
proc genAndOr(c: PCtx; n: PNode; opc: TOpcode; dest: var TDest) =
# asgn dest, a
# tjmp|fjmp L1
# asgn dest, b
# L1:
if dest < 0: dest = getTemp(c, n.typ)
c.gen(n.sons[1], dest)
let L1 = c.xjmp(n, opc, dest)
c.gen(n.sons[2], dest)
let copyBack = dest < 0 or not isTemp(c, dest)
let tmp = if copyBack:
getTemp(c, n.typ)
else:
TRegister dest
c.gen(n.sons[1], tmp)
let L1 = c.xjmp(n, opc, tmp)
c.gen(n.sons[2], tmp)
c.patch(L1)
if dest < 0:
dest = tmp
elif copyBack:
c.gABC(n, opcAsgnInt, dest, tmp)
freeTemp(c, tmp)
proc canonValue*(n: PNode): PNode =
result = n
@ -1469,9 +1481,6 @@ proc checkCanEval(c: PCtx; n: PNode) =
skIterator} and sfForward in s.flags:
cannotEval(c, n)
proc isTemp(c: PCtx; dest: TDest): bool =
result = dest >= 0 and c.prc.slots[dest].kind >= slotTempUnknown
template needsAdditionalCopy(n): untyped =
not c.isTemp(dest) and not fitsRegister(n.typ)