Skip to content

Commit 29fcc82

Browse files
brksipma
authored andcommitted
Avoid moving labels in a block
When an empty instrs node in the middle of a block had associated labels, we were moving those labels to the start of the block, which is incorrect. The labels should be kept in order.
1 parent fb33541 commit 29fcc82

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

chb/ast/ASTSerializer.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,19 @@ def is_empty_instr_sequence(s: AST.ASTStmt) -> bool:
333333
return False
334334
return len(cast(AST.ASTInstrSequence, s).instructions) == 0
335335

336-
# Make sure we don't drop labels from empty instr sequences.
337-
for s in stmt.stmts:
338-
if is_empty_instr_sequence(s):
339-
labels.extend(s.labels)
340-
341336
if len(labels) > 0:
342337
node["labelcount"] = len(labels)
343338
for label in labels:
344339
args.append(label.index(self))
345-
args.extend(s.index(self) for s in stmt.stmts
346-
if not is_empty_instr_sequence(s))
340+
341+
for s in stmt.stmts:
342+
if is_empty_instr_sequence(s):
343+
# Make sure we don't drop labels from empty instr sequences.
344+
for label in s.labels:
345+
args.append(label.index(self))
346+
else:
347+
args.append(s.index(self))
348+
347349
return self.add(tags, args, node)
348350

349351
def index_loop_stmt(self, stmt: AST.ASTLoop) -> int:

0 commit comments

Comments
 (0)