mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
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:
@@ -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
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)
|
||||
Reference in New Issue
Block a user