@@ -336,17 +336,27 @@ impl IRGraphConstructor {
336336 let mut loop_body = Block :: new ( "while-body" . to_string ( ) ) ;
337337 loop_body. register_entry_point ( self . current_block_index , entry_false_projection) ;
338338 let loop_body_index = self . graph . register_block ( loop_body) ;
339+ let loop_back_block = Block :: new ( "while-condition" . to_string ( ) ) ;
340+ let loop_back_block_index = self . graph . register_block ( loop_back_block) ;
339341 let mut following_block = Block :: new ( "while-following" . to_string ( ) ) ;
340342 following_block
341343 . register_entry_point ( self . current_block_index , entry_true_projection) ;
342344 let following_block_index = self . graph . register_block ( following_block) ;
343345 self . seal_block ( self . current_block_index ) ;
344346
345347 self . current_block_index = loop_body_index;
346- self . active_loop_entries . push ( loop_body_index ) ;
348+ self . active_loop_entries . push ( loop_back_block_index ) ;
347349 self . active_loop_exits . push ( following_block_index) ;
348350 self . convert_boxed ( expression) ;
351+ let loop_body_jump = self . create_jump ( ) ;
352+ self . graph
353+ . get_block_mut ( loop_back_block_index)
354+ . register_entry_point ( loop_body_index, loop_body_jump) ;
355+ self . active_loop_entries . pop ( ) ;
356+ self . active_loop_exits . pop ( ) ;
349357
358+ self . current_block_index = loop_back_block_index;
359+ self . seal_block ( loop_back_block_index) ;
350360 let condition_node = self . convert_boxed ( condition) ?;
351361 let conditional_jump = self . create_conditional_jump ( condition_node) ;
352362
@@ -355,11 +365,11 @@ impl IRGraphConstructor {
355365
356366 self . graph
357367 . get_block_mut ( loop_body_index)
358- . register_entry_point ( loop_body_index , true_projection) ;
368+ . register_entry_point ( loop_back_block_index , true_projection) ;
359369
360370 self . graph
361371 . get_block_mut ( following_block_index)
362- . register_entry_point ( loop_body_index , false_projection) ;
372+ . register_entry_point ( loop_back_block_index , false_projection) ;
363373 self . seal_block ( loop_body_index) ;
364374 self . current_block_index = following_block_index;
365375 self . seal_block ( self . current_block_index ) ;
0 commit comments