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:
flywind
2022-06-29 22:37:24 +08:00
committed by GitHub
parent 8a344cb25b
commit bcff13debc
2 changed files with 46 additions and 1 deletions

View File

@@ -851,7 +851,7 @@ proc computeLiveRanges(c: var Partitions; n: PNode) =
# connect(graph, cursorVar)
inc c.inLoop
for child in n: computeLiveRanges(c, child)
inc c.inLoop
dec c.inLoop
of nkElifBranch, nkElifExpr, nkElse, nkOfBranch:
inc c.inConditional
for child in n: computeLiveRanges(c, child)

45
tests/arc/tcursorloop.nim Normal file
View 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)