Skip to content

pystats asserts on valid register-cached uop IDs #159511

Open

Description

@cocolato

Bug report

UOP_STAT_INC in Include/internal/pycore_stats.h asserts that the uop ID is below 512.

#define UOP_STAT_INC(opname, name) \
do { \
PyStats *s = _PyStats_GET(); \
if (s) { \
assert(opname < 512); \
s->optimization_stats.opcode[opname].name++; \

Register-cached uop IDs start at 655, so the opname < 512 assertion in UOP_STAT_INC, which predates them, fails on the first uop executed while pystats collection is on.

The statistics array already has PYSTATS_MAX_UOP_ID + 1 entries, with PYSTATS_MAX_UOP_ID set to 2000. The assertion should use that bound.

Reaching the assertion requires the terminator fix from PR #148220; without it, the reproducer aborts earlier with No terminating instruction.

Reproduction

Configure:

--enable-pystats --enable-experimental-jit --with-pydebug

repro.py:

def f(n):
    total = 0
    for i in range(n):
        total += i
    return total

assert f(100_000) == 4_999_950_000

Error:

Assertion failure at line 167 of executor_cases.c.h

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions