File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed 
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -842,16 +842,18 @@ fn maybe_loop_headers(body: &Body<'_>) -> DenseBitSet<BasicBlock> {
842842    let  mut  maybe_loop_headers = DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ; 
843843    let  mut  visited = DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ; 
844844    for  ( bb,  bbdata)  in  traversal:: postorder ( body)  { 
845-         let  _new = visited. insert ( bb) ; 
846-         debug_assert ! ( _new) ; 
847- 
848845        // Post-order means we visit successors before the block for acyclic CFGs. 
849846        // If the successor is not visited yet, consider it a loop header. 
850847        for  succ in  bbdata. terminator ( ) . successors ( )  { 
851848            if  !visited. contains ( succ)  { 
852849                maybe_loop_headers. insert ( succ) ; 
853850            } 
854851        } 
852+ 
853+         // Only mark `bb` as visited after we checked the successors, in case we have a self-loop. 
854+         //     bb1: goto -> bb1; 
855+         let  _new = visited. insert ( bb) ; 
856+         debug_assert ! ( _new) ; 
855857    } 
856858
857859    maybe_loop_headers
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments