mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	gh-107901: Fix missing line number on BACKWARD_JUMP at the end of a for loop (#108242)
This commit is contained in:
		
							parent
							
								
									e6db23f66d
								
							
						
					
					
						commit
						a1cc74c4ee
					
				
					 3 changed files with 16 additions and 1 deletions
				
			
		|  | @ -1031,6 +1031,20 @@ async def test(aseq): | ||||||
|         code_lines = self.get_code_lines(test.__code__) |         code_lines = self.get_code_lines(test.__code__) | ||||||
|         self.assertEqual(expected_lines, code_lines) |         self.assertEqual(expected_lines, code_lines) | ||||||
| 
 | 
 | ||||||
|  |     def test_lineno_of_backward_jump(self): | ||||||
|  |         # Issue gh-107901 | ||||||
|  |         def f(): | ||||||
|  |             for i in x: | ||||||
|  |                 if y: | ||||||
|  |                     pass | ||||||
|  | 
 | ||||||
|  |         linenos = list(inst.positions.lineno | ||||||
|  |                        for inst in dis.get_instructions(f.__code__) | ||||||
|  |                        if inst.opname == 'JUMP_BACKWARD') | ||||||
|  | 
 | ||||||
|  |         self.assertTrue(len(linenos) > 0) | ||||||
|  |         self.assertTrue(all(l is not None for l in linenos)) | ||||||
|  | 
 | ||||||
|     def test_big_dict_literal(self): |     def test_big_dict_literal(self): | ||||||
|         # The compiler has a flushing point in "compiler_dict" that calls compiles |         # The compiler has a flushing point in "compiler_dict" that calls compiles | ||||||
|         # a portion of the dictionary literal when the loop that iterates over the items |         # a portion of the dictionary literal when the loop that iterates over the items | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | Fix missing line number on :opcode:`JUMP_BACKWARD` at the end of a for loop. | ||||||
|  | @ -531,7 +531,7 @@ normalize_jumps_in_block(cfg_builder *g, basicblock *b) { | ||||||
|     if (backwards_jump == NULL) { |     if (backwards_jump == NULL) { | ||||||
|         return ERROR; |         return ERROR; | ||||||
|     } |     } | ||||||
|     basicblock_addop(backwards_jump, JUMP, target->b_label.id, NO_LOCATION); |     basicblock_addop(backwards_jump, JUMP, target->b_label.id, last->i_loc); | ||||||
|     backwards_jump->b_instr[0].i_target = target; |     backwards_jump->b_instr[0].i_target = target; | ||||||
|     last->i_opcode = reversed_opcode; |     last->i_opcode = reversed_opcode; | ||||||
|     last->i_target = b->b_next; |     last->i_target = b->b_next; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Irit Katriel
						Irit Katriel