Skip to content

Error when decompiling loop inside if-else #322

Open
@ghost

Description

I was trying to decompile a pyc that I had, but it had a few errors. I managed to manually decompile it though and narrowed it down to code that looks like this:

def func(val):
    if val == 0:
        while True:
            pass
    else:
        pass

When I compile this with python3 -m compileall . and then attempt to decompile, I get a 'parse error':

# uncompyle6 version 3.7.2
# Python bytecode 3.8 (3413)
# Decompiled from: Python 3.7.7 (default, Jun 28 2020, 13:00:53) 
# [GCC 9.3.0]
# Embedded file name: ./code.py
# Compiled at: 2020-06-28 16:30:43
# Size of source mod 2**32: 92 bytes
Instruction context:
   
 L.   4         8  JUMP_BACK             8  'to 8'
->                10  JUMP_FORWARD         12  'to 12'
                12_0  COME_FROM            10  '10'


def func--- This code section failed: ---

 L.   2         0  LOAD_FAST                'val'
                2  LOAD_CONST               0
                4  COMPARE_OP               ==
                6  POP_JUMP_IF_FALSE    12  'to 12'

 L.   4         8  JUMP_BACK             8  'to 8'
               10  JUMP_FORWARD         12  'to 12'
             12_0  COME_FROM            10  '10'
             12_1  COME_FROM             6  '6'

Parse error at or near `JUMP_FORWARD' instruction at offset 10

# file __pycache__/code.cpython-38.pyc
# Deparsing stopped due to parse error

Here is the disassembly of that code:

  1           0 LOAD_CONST               0 (<code object func at 0x7ffac2d20b30, file "code.py", line 1>)
              2 LOAD_CONST               1 ('func')
              4 MAKE_FUNCTION            0
              6 STORE_NAME               0 (func)
              8 LOAD_CONST               2 (None)
             10 RETURN_VALUE

Disassembly of <code object func at 0x7ffac2d20b30, file "code.py", line 1>:
  2           0 LOAD_FAST                0 (val)
              2 LOAD_CONST               1 (0)
              4 COMPARE_OP               2 (==)
              6 POP_JUMP_IF_FALSE       12

  4     >>    8 JUMP_ABSOLUTE            8
             10 JUMP_FORWARD             0 (to 12)

  6     >>   12 LOAD_CONST               0 (None)
             14 RETURN_VALUE

Hopefully this issue can be fixed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Control FlowProblem has to do with bad control-flow detectionPython 3.7Volunteer wantedVolunteer wanted to fix if a bug or to implement if a new feature.Works on decompyle3

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions