diff options
-rw-r--r-- | compiler/destroyer.nim | 10 | ||||
-rw-r--r-- | compiler/dfa.nim | 15 | ||||
-rw-r--r-- | tests/destructor/tmove_objconstr.nim | 9 |
3 files changed, 24 insertions, 10 deletions
diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index 06d4dcbef..e21d532ea 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -139,7 +139,7 @@ proc isLastRead(s: PSym; c: var Con; pc, comesFrom: int): int = of def: if c.g[pc].sym == s: # the path lead to a redefinition of 's' --> abandon it. - return pc + return high(int) inc pc of use: if c.g[pc].sym == s: @@ -150,14 +150,16 @@ proc isLastRead(s: PSym; c: var Con; pc, comesFrom: int): int = pc = pc + c.g[pc].dest of fork: # every branch must lead to the last read of the location: - let variantA = isLastRead(s, c, pc+1, pc) + var variantA = isLastRead(s, c, pc+1, pc) if variantA < 0: return -1 let variantB = isLastRead(s, c, pc + c.g[pc].dest, pc) if variantB < 0: return -1 - pc = variantA+1 + elif variantA == high(int): + variantA = variantB + pc = variantA of InstrKind.join: let dest = pc + c.g[pc].dest - if dest == comesFrom: return pc + if dest == comesFrom: return pc + 1 inc pc return pc diff --git a/compiler/dfa.nim b/compiler/dfa.nim index f34981000..462cf0fb7 100644 --- a/compiler/dfa.nim +++ b/compiler/dfa.nim @@ -74,7 +74,7 @@ proc codeListing(c: ControlFlowGraph, result: var string, start=0; last = -1) = while i <= last: if i in jumpTargets: result.add("L" & $i & ":\n") result.add "\t" - result.add $c[i].kind + result.add ($i & " " & $c[i].kind) result.add "\t" case c[i].kind of def, use: @@ -540,13 +540,17 @@ proc genTry(c: var Con; n: PNode) = c.gen(fin.sons[0]) doAssert(c.forks.len == oldLen) +template genNoReturn(c: var Con; n: PNode) = + # leave the graph + c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len) + proc genRaise(c: var Con; n: PNode) = genJoins(c, n) gen(c, n.sons[0]) if c.inTryStmt > 0: c.tryStmtFixups.add c.gotoI(n) else: - c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len) + genNoReturn(c, n) proc genImplicitReturn(c: var Con) = if c.owner.kind in {skProc, skFunc, skMethod, skIterator, skConverter} and resultPos < c.owner.ast.len: @@ -558,7 +562,7 @@ proc genReturn(c: var Con; n: PNode) = gen(c, n.sons[0]) else: genImplicitReturn(c) - c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len) + genNoReturn(c, n) const InterestingSyms = {skVar, skResult, skLet, skParam} @@ -612,9 +616,6 @@ proc genMagic(c: var Con; n: PNode; m: TMagic) = of mNew, mNewFinalize: genDef(c, n[1]) for i in 2..<n.len: gen(c, n[i]) - of mExit: - genCall(c, n) - c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len) else: genCall(c, n) @@ -639,6 +640,8 @@ proc gen(c: var Con; n: PNode) = genMagic(c, n, s.magic) else: genCall(c, n) + if sfNoReturn in n.sons[0].sym.flags: + genNoReturn(c, n) else: genCall(c, n) of nkCharLit..nkNilLit: discard diff --git a/tests/destructor/tmove_objconstr.nim b/tests/destructor/tmove_objconstr.nim index 875f78283..7e2b765fc 100644 --- a/tests/destructor/tmove_objconstr.nim +++ b/tests/destructor/tmove_objconstr.nim @@ -166,3 +166,12 @@ seq4 = var ii = 1 let arr2 = [newMySeq(2, 5.0), if i > 1: newMySeq(3, 1.0) else: newMySeq(0, 0.0)] var seqOfSeq2 = @[newMySeq(2, 5.0), newMySeq(3, 1.0)] + + +## issue #10462 +proc myfuncLoop(x: int): MySeqNonCopyable = + for i in 0..<x: + var cc = newMySeq(i, 5.0) + result = cc + +discard myfuncLoop(3) \ No newline at end of file |