Skip to content

Handle Python 3.11 exception opcodes in AST builder#599

Merged
zrax merged 2 commits intozrax:masterfrom
daiche330-png:wip/python311-exception-opcodes-20260405
Apr 7, 2026
Merged

Handle Python 3.11 exception opcodes in AST builder#599
zrax merged 2 commits intozrax:masterfrom
daiche330-png:wip/python311-exception-opcodes-20260405

Conversation

@daiche330-png
Copy link
Copy Markdown
Contributor

@daiche330-png daiche330-png commented Apr 5, 2026

What changed

  • add AST builder handling for Python 3.11 exception-related opcodes:
    • PUSH_EXC_INFO
    • CHECK_EXC_MATCH
    • RERAISE
    • RERAISE_A
    • BEFORE_WITH
  • map CHECK_EXC_MATCH to ASTCompare::CMP_EXCEPTION
  • synthesize try/except block structure from Python 3.11 exception table entries when legacy setup opcodes are absent
  • preserve exception handler bounds so handler cleanup opcodes do not leak into decompiled source
  • treat RERAISE cleanup opcodes as internal control-flow cleanup rather than emitted source statements
  • add a Python 3.11 regression test for typed try/except

Why this changed

The AST builder did not recognize several Python 3.11 exception opcodes, and it also relied on legacy setup opcodes that are no longer present in 3.11 bytecode. That meant decompilation could stop early, lose except clauses, or emit cleanup artifacts instead of valid try/except source.

Impact

  • improves compatibility with Python 3.11 bytecode around typed exception handling
  • restores try/except structure from exception-table driven bytecode
  • adds regression coverage for the new path without changing existing expected-failure coverage

Validation

  • inspected and updated the opcode-specific AST builder path in ASTree.cpp
  • configured a fresh build directory with:
    • /Users/miyazakidaichi/anaconda3/envs/dits2/lib/python3.11/site-packages/cmake/data/bin/cmake -S /Users/miyazakidaichi/Nextcloud/dev/tmp_pycdc -B /tmp/tmp_pycdc_build_codex
  • built successfully with:
    • make -C /tmp/tmp_pycdc_build_codex -j4
  • verified the new regression test in isolation with:
    • python3 /Users/miyazakidaichi/Nextcloud/dev/tmp_pycdc/tests/run_tests.py --filter test_exception_match_py311 --jobs 1
  • ran the full test target successfully with:
    • make -C /tmp/tmp_pycdc_build_codex check JOBS=4
  • existing expected-failure (XFAIL) cases still appear in the suite output

@daiche330-png daiche330-png marked this pull request as ready for review April 6, 2026 00:09
@zrax zrax merged commit b428976 into zrax:master Apr 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants