3.5+ handle then before "if" jump going to loop

This commit is contained in:
rocky
2018-03-27 19:24:29 -04:00
parent aa4416571b
commit d90c44b454
5 changed files with 36 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,23 @@
# From python 3.5.5 telnetlib
# The bug is the end of a "then" jumping
# back to the loop which could look like
# a "continue" and also not like a then/else
# break
def process_rawq(self, cmd, cmd2):
while self.rawq:
if self.iacseq:
if cmd:
pass
elif cmd2:
if self.option_callback:
self.option = 2
else:
self.option = 3
# From python 3.5.5 telnetlib
def listener(data):
while 1:
if data:
data = 1
else:
data = 2

View File

@@ -102,7 +102,14 @@ class Python35Parser(Python34Parser):
return_if_stmt ::= ret_expr RETURN_END_IF POP_BLOCK
jb_else ::= JUMP_BACK ELSE
ifelsestmtc ::= testexpr c_stmts_opt JUMP_FORWARD else_suitec
ifelsestmtl ::= testexpr c_stmts_opt jb_else else_suitel
# 3.5 Has jump optimization which can route the end of an
# "if/then" back to to a loop just before an else.
jump_absolute_else ::= jb_else
jump_absolute_else ::= CONTINUE ELSE
# ifstmt ::= testexpr c_stmts_opt

View File

@@ -910,7 +910,8 @@ class Scanner3(Scanner):
if offset in self.ignore_if:
return
if (code[pre_rtarget] == self.opc.JUMP_ABSOLUTE and
rtarget_is_ja = code[pre_rtarget] == self.opc.JUMP_ABSOLUTE
if ( rtarget_is_ja and
pre_rtarget in self.stmts and
pre_rtarget != offset and
prev_op[pre_rtarget] != offset and
@@ -930,10 +931,13 @@ class Scanner3(Scanner):
# or a conditional assignment like:
# x = 1 if x else 2
#
# For 3.5, in addition the JUMP_FORWARD above we could have
# JUMP_BACK or CONTINUE
#
# There are other contexts we may need to consider
# like whether the target is "END_FINALLY"
# or if the condition jump is to a forward location
if self.is_jump_forward(pre_rtarget):
if self.is_jump_forward(pre_rtarget) or (rtarget_is_ja and self.version >= 3.5):
if_end = self.get_target(pre_rtarget)
# If the jump target is back, we are looping