mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	[3.13] gh-124871: fix 'visited' tracking in compiler's reachability analysis (GH-124952) (#124977)
gh-124871: fix 'visited' tracking in compiler's reachability analysis (GH-124952)
(cherry picked from commit f474391b26)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
			
			
This commit is contained in:
		
							parent
							
								
									dd4e62e35f
								
							
						
					
					
						commit
						b87aea6b0d
					
				
					 3 changed files with 18 additions and 2 deletions
				
			
		| 
						 | 
					@ -476,6 +476,19 @@ def test_dead_code_with_except_handler_compiles(self):
 | 
				
			||||||
                    x = 2
 | 
					                    x = 2
 | 
				
			||||||
               """), '<eval>', 'exec')
 | 
					               """), '<eval>', 'exec')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_try_except_in_while_with_chained_condition_compiles(self):
 | 
				
			||||||
 | 
					        # see gh-124871
 | 
				
			||||||
 | 
					        compile(textwrap.dedent("""
 | 
				
			||||||
 | 
					            name_1, name_2, name_3 = 1, 2, 3
 | 
				
			||||||
 | 
					            while name_3 <= name_2 > name_1:
 | 
				
			||||||
 | 
					                try:
 | 
				
			||||||
 | 
					                    raise
 | 
				
			||||||
 | 
					                except:
 | 
				
			||||||
 | 
					                    pass
 | 
				
			||||||
 | 
					                finally:
 | 
				
			||||||
 | 
					                    pass
 | 
				
			||||||
 | 
					            """), '<eval>', 'exec')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_compile_invalid_namedexpr(self):
 | 
					    def test_compile_invalid_namedexpr(self):
 | 
				
			||||||
        # gh-109351
 | 
					        # gh-109351
 | 
				
			||||||
        m = ast.Module(
 | 
					        m = ast.Module(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					Fix compiler bug (in some versions of 3.13) where an assertion fails during reachability
 | 
				
			||||||
 | 
					analysis.
 | 
				
			||||||
| 
						 | 
					@ -960,13 +960,14 @@ remove_unreachable(basicblock *entryblock) {
 | 
				
			||||||
    basicblock **sp = stack;
 | 
					    basicblock **sp = stack;
 | 
				
			||||||
    entryblock->b_predecessors = 1;
 | 
					    entryblock->b_predecessors = 1;
 | 
				
			||||||
    *sp++ = entryblock;
 | 
					    *sp++ = entryblock;
 | 
				
			||||||
 | 
					    entryblock->b_visited = 1;
 | 
				
			||||||
    while (sp > stack) {
 | 
					    while (sp > stack) {
 | 
				
			||||||
        basicblock *b = *(--sp);
 | 
					        basicblock *b = *(--sp);
 | 
				
			||||||
        b->b_visited = 1;
 | 
					 | 
				
			||||||
        if (b->b_next && BB_HAS_FALLTHROUGH(b)) {
 | 
					        if (b->b_next && BB_HAS_FALLTHROUGH(b)) {
 | 
				
			||||||
            if (!b->b_next->b_visited) {
 | 
					            if (!b->b_next->b_visited) {
 | 
				
			||||||
                assert(b->b_next->b_predecessors == 0);
 | 
					                assert(b->b_next->b_predecessors == 0);
 | 
				
			||||||
                *sp++ = b->b_next;
 | 
					                *sp++ = b->b_next;
 | 
				
			||||||
 | 
					                b->b_next->b_visited = 1;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            b->b_next->b_predecessors++;
 | 
					            b->b_next->b_predecessors++;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -976,8 +977,8 @@ remove_unreachable(basicblock *entryblock) {
 | 
				
			||||||
            if (is_jump(instr) || is_block_push(instr)) {
 | 
					            if (is_jump(instr) || is_block_push(instr)) {
 | 
				
			||||||
                target = instr->i_target;
 | 
					                target = instr->i_target;
 | 
				
			||||||
                if (!target->b_visited) {
 | 
					                if (!target->b_visited) {
 | 
				
			||||||
                    assert(target->b_predecessors == 0 || target == b->b_next);
 | 
					 | 
				
			||||||
                    *sp++ = target;
 | 
					                    *sp++ = target;
 | 
				
			||||||
 | 
					                    target->b_visited = 1;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                target->b_predecessors++;
 | 
					                target->b_predecessors++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue