zrax / pycdc

C++ python bytecode disassembler and decompiler
GNU General Public License v3.0
3.25k stars 625 forks source link

decompiled incorrectly in evaluating a logical expression #33

Open caot opened 11 years ago

caot commented 11 years ago

Input:

c = x and y

output:

if x:
    pass
c = y
rocky commented 7 years ago

I get this output on all versions I have tried: 2.3, 2.6, 2.7, 3,3, 3.5

uncompyle6 doesn't have this problem (although it has many others). On the hope that this is useful, a parse of is is below for comparison:

$ ./bin/uncompyle6 -t /tmp/bug3-3.5.pyc
# uncompyle6 version 2.9.6
# Python bytecode 3.5 (3350)
# Decompiled from: Python 3.3.6 (default, Dec 26 2015, 07:55:08) 
# [GCC 5.2.1 20151010]
# Embedded file name: exec
# Compiled at: 2016-11-27 10:19:55
# Size of source mod 2**32: 12 bytes
stmts
    sstmt
        stmt
            assign (2)
                 0. expr
                    and (4)
                         0. expr
                            L.   1       0  LOAD_NAME                'x'
                         1.              3  JUMP_IF_FALSE_OR_POP     9  'to 9'
                         2. expr
                                         6  LOAD_NAME                'y'
                         3.            9_0  COME_FROM                '3'
                 1. designator
                                 9  STORE_NAME               'c'
c = x and y
# okay decompiling /tmp/bug3-3.5.pyc

The pseudo-instruction COME_FROM is added by the program and is not part of the disassembly. Python versions before 2.7 give the same thing but JUMP_IF_FALSE_OR_POP is replaced with a JUMP_IF_FALSE and POP_TOP pair.