@@ -772,7 +772,7 @@ opcode_stack_effect(int opcode, int oparg)
772772 case UNPACK_EX :
773773 return (oparg & 0xFF ) + (oparg >>8 );
774774 case FOR_ITER :
775- return 1 ;
775+ return 1 ; /* or -1, at end of iterator */
776776
777777 case STORE_ATTR :
778778 return -2 ;
@@ -799,7 +799,7 @@ opcode_stack_effect(int opcode, int oparg)
799799 case COMPARE_OP :
800800 return -1 ;
801801 case IMPORT_NAME :
802- return 0 ;
802+ return -1 ;
803803 case IMPORT_FROM :
804804 return 1 ;
805805
@@ -3546,7 +3546,7 @@ dfs(struct compiler *c, basicblock *b, struct assembler *a)
35463546static int
35473547stackdepth_walk (struct compiler * c , basicblock * b , int depth , int maxdepth )
35483548{
3549- int i ;
3549+ int i , target_depth ;
35503550 struct instr * instr ;
35513551 if (b -> b_seen || b -> b_startdepth >= depth )
35523552 return maxdepth ;
@@ -3559,8 +3559,17 @@ stackdepth_walk(struct compiler *c, basicblock *b, int depth, int maxdepth)
35593559 maxdepth = depth ;
35603560 assert (depth >= 0 ); /* invalid code or bug in stackdepth() */
35613561 if (instr -> i_jrel || instr -> i_jabs ) {
3562+ target_depth = depth ;
3563+ if (instr -> i_opcode == FOR_ITER ) {
3564+ target_depth = depth - 2 ;
3565+ } else if (instr -> i_opcode == SETUP_FINALLY ||
3566+ instr -> i_opcode == SETUP_EXCEPT ) {
3567+ target_depth = depth + 3 ;
3568+ if (target_depth > maxdepth )
3569+ maxdepth = target_depth ;
3570+ }
35623571 maxdepth = stackdepth_walk (c , instr -> i_target ,
3563- depth , maxdepth );
3572+ target_depth , maxdepth );
35643573 if (instr -> i_opcode == JUMP_ABSOLUTE ||
35653574 instr -> i_opcode == JUMP_FORWARD ) {
35663575 goto out ; /* remaining code is dead */
0 commit comments