File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11ChangeLog
22=========
33
4+ 2025-04-14: Version 0.16.2
5+ --------------------------
6+
7+ Bugfixes:
8+
9+ - fix ControlFlowGraph dead block detection by accounting for fall-through
10+ edges. PR #161
11+
4122025-01-21: Version 0.16.1
513--------------------------
614
Original file line number Diff line number Diff line change @@ -731,12 +731,18 @@ def get_dead_blocks(self) -> List[BasicBlock]:
731731 if id (block ) in seen_block_ids :
732732 continue
733733 seen_block_ids .add (id (block ))
734+ fall_through = True
734735 for i in block :
735- if isinstance (i , Instr ) and isinstance (i .arg , BasicBlock ):
736- stack .append (i .arg )
736+ if isinstance (i , Instr ):
737+ if isinstance (i .arg , BasicBlock ):
738+ stack .append (i .arg )
739+ if i .is_final ():
740+ fall_through = False
737741 elif isinstance (i , TryBegin ):
738742 assert isinstance (i .target , BasicBlock )
739743 stack .append (i .target )
744+ if fall_through and block .next_block :
745+ stack .append (block .next_block )
740746
741747 return [b for b in self if id (b ) not in seen_block_ids ]
742748
Original file line number Diff line number Diff line change @@ -712,6 +712,20 @@ def test_get_block_index(self):
712712 other_block = BasicBlock ()
713713 self .assertRaises (ValueError , blocks .get_block_index , other_block )
714714
715+ def test_get_dead_blocks (self ):
716+ def condition ():
717+ pass
718+
719+ def test ():
720+ if condition ():
721+ print ("1" )
722+ else :
723+ print ("2" )
724+
725+ bytecode = Bytecode .from_code (test .__code__ )
726+ cfg = ControlFlowGraph .from_bytecode (bytecode )
727+ assert len (cfg .get_dead_blocks ()) == 0
728+
715729
716730class CFGStacksizeComputationTests (TestCase ):
717731 def check_stack_size (self , func ):
You can’t perform that action at this time.
0 commit comments