dec inLoop after exiting the while scope in computeLiveRanges [backport] (#19918)
* dec inLoop after exiting the while scope in computeLiveRanges * add testcase
This commit is contained in:
parent
8a344cb25b
commit
bcff13debc
2 changed files with 46 additions and 1 deletions
|
|
@ -851,7 +851,7 @@ proc computeLiveRanges(c: var Partitions; n: PNode) =
|
||||||
# connect(graph, cursorVar)
|
# connect(graph, cursorVar)
|
||||||
inc c.inLoop
|
inc c.inLoop
|
||||||
for child in n: computeLiveRanges(c, child)
|
for child in n: computeLiveRanges(c, child)
|
||||||
inc c.inLoop
|
dec c.inLoop
|
||||||
of nkElifBranch, nkElifExpr, nkElse, nkOfBranch:
|
of nkElifBranch, nkElifExpr, nkElse, nkOfBranch:
|
||||||
inc c.inConditional
|
inc c.inConditional
|
||||||
for child in n: computeLiveRanges(c, child)
|
for child in n: computeLiveRanges(c, child)
|
||||||
|
|
|
||||||
45
tests/arc/tcursorloop.nim
Normal file
45
tests/arc/tcursorloop.nim
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
discard """
|
||||||
|
cmd: '''nim c --gc:arc --expandArc:traverse --hint:Performance:off $file'''
|
||||||
|
nimout: '''
|
||||||
|
--expandArc: traverse
|
||||||
|
|
||||||
|
var
|
||||||
|
it
|
||||||
|
jt_cursor
|
||||||
|
try:
|
||||||
|
`=copy`(it, root)
|
||||||
|
block :tmp:
|
||||||
|
while (
|
||||||
|
not (it == nil)):
|
||||||
|
if true:
|
||||||
|
echo [it.s]
|
||||||
|
`=copy`(it, it.ri)
|
||||||
|
jt_cursor = root
|
||||||
|
if (
|
||||||
|
not (jt_cursor == nil)):
|
||||||
|
echo [jt_cursor.s]
|
||||||
|
jt_cursor = jt_cursor.ri
|
||||||
|
finally:
|
||||||
|
`=destroy`(it)
|
||||||
|
-- end of expandArc ------------------------
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Node = ref object
|
||||||
|
le, ri: Node
|
||||||
|
s: string
|
||||||
|
|
||||||
|
proc traverse(root: Node) =
|
||||||
|
var it = root
|
||||||
|
while it != nil:
|
||||||
|
if true:
|
||||||
|
echo it.s
|
||||||
|
it = it.ri
|
||||||
|
|
||||||
|
var jt = root
|
||||||
|
if jt != nil:
|
||||||
|
echo jt.s
|
||||||
|
jt = jt.ri
|
||||||
|
|
||||||
|
traverse(nil)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue