python / python/cpython

Assertion failure at Python/instruction_sequence.c:121: `int _PyInstructionSequence_Addop(instr_sequence *, int, int, location): Assertion 'OPCODE_HAS_ARG(opcode) || HAS_TARGET(opcode) || oparg == 0' failed`

Open
#142,661 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core tests type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Crash report

What happened?
import unittest
from test.support.bytecode_helper import CodegenTestCase
class IsolatedCodeGenTests(CodegenTestCase):
    def assertInstructionsMatch_recursive(self, insts, expected_insts):
        self.assertInstructionsMatch(insts, expected_insts)
    def codegen_test(self, snippet, expected_insts):
        import ast
        a = ast.parse(snippet, 'my_file.py', 'exec')
        insts = self.generate_code(a)
        self.assertInstructionsMatch_recursive(insts, expected_insts)
    def test_if_expression(self):
        snippet = '42 if True else 24'
        expected = [('RESUME', 0, 0), ('ANNOTATIONS_PLACEHOLDER', None), ('LOAD_CONST', 0, 1), ('TO_BOOL', 256, 1), ('POP_JUMP_IF_FALSE', (false_lbl := 1), 1), ('LOAD_CONST', 1, 1), ('\x00', (exit_lbl := self.Label())), false_lbl, ('', 255, 1), exit_lbl, ('POP_TOP', None), ('LOAD_CONST', 1), ('RETURN_VALUE', None)]
        self.codegen_test(snippet, expected)

if __name__ == "__main__":
    unittest.main(verbosity=0)
python: ../Python/instruction_sequence.c:121: int _PyInstructionSequence_Addop(instr_sequence *, int, int, location): Assertion `OPCODE_HAS_ARG(opcode) || HAS_TARGET(opcode) || oparg == 0' failed.
CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the assertion at Python/instruction_sequence.c:121 and reproduce it using the provided IsolatedCodeGenTests snippet through CodegenTestCase.generate_code(). Trace the generated instructions for the conditional expression and determine why the assertion is reached with its reported opcode and argument. Done means the reproducer no longer aborts and a regression test covers the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.