Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3792,6 +3792,67 @@ def __next__(self):
"""), PYTHON_JIT="1", PYTHON_JIT_STRESS="1")
self.assertEqual(result[0].rc, 0, result)

def test_143820(self):
# https://github.com/python/cpython/issues/143358

result = script_helper.run_python_until_end('-c', textwrap.dedent(f"""
import sys
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems like a lot of extraneous stuff in this test, and no check that the STORE_FAST is overwritten by an ENTER_EXECUTOR.

import random

int_v1 = 981679
int_v2 = -3791744241805517
any_v3 = 939.217

def f1(): int_v1 ^ int_v1

for i_f1 in range(300):
f1()

def f2():
class Int(int):
def __index__(self):...

inf = float('inf')
nzero = -0
zero = 0.0
dummy = 0
print('', file=sys.stderr)

def f_0_dc_6103(p): return p + 1
def f_1_dc_6103(p): return f_0_dc_6103(p) + 1
def f_2_dc_6103(p): return f_1_dc_6103(p) + 1
def f_3_dc_6103(p): return f_2_dc_6103(p) + 1
def f_4_dc_6103(p): return f_3_dc_6103(p) + 1
def f_5_dc_6103(p): return f_4_dc_6103(p) + 1
def f_6_dc_6103(p): return f_5_dc_6103(p) + 1
def f_7_dc_6103(p): return f_6_dc_6103(p) + 1
def f_8_dc_6103(p): return f_7_dc_6103(p) + 1
def f_9_dc_6103(p): return f_8_dc_6103(p) + 1

if inf == inf: dummy += 1
s = ''
try:
for _ in range(10):
s += ''
s += 'y'
except Exception: pass
int_v1 ^ int_v1
int_v1 ^ int_v1
int_v1 ^ int_v1
int_v2 - int_v1
int_v2 - int_v1
int_v2 - int_v1
int_v2 - int_v1
int_v2 - int_v1
not any_v3
not any_v3
not any_v3

for i_f2 in range(300):
f2()
"""), PYTHON_JIT="1", PYTHON_JIT_STRESS="1")
self.assertEqual(result[0].rc, 0, result)

def global_identity(x):
return x

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug in JIT builds where executors can be inserted after certain super instructions.
9 changes: 8 additions & 1 deletion Modules/_testinternalcapi/test_cases.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,15 @@
assert(PyUnicode_CheckExact(PyStackRef_AsPyObjectBorrow(right)));
int next_oparg;
#if TIER_ONE
assert(next_instr->op.code == STORE_FAST);
next_oparg = next_instr->op.arg;
#if _Py_TIER2

if (next_instr->op.code == ENTER_EXECUTOR) {
_PyExecutorObject *exec = _PyFrame_GetCode(frame)->co_executors->executors[next_oparg];
next_oparg = exec->vm_data.oparg;
}
#endif
assert(next_instr->op.code == STORE_FAST || next_instr->op.code == ENTER_EXECUTOR);
#else
next_oparg = (int)CURRENT_OPERAND0_16();
#endif
Expand Down
10 changes: 9 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,16 @@ dummy_func(

int next_oparg;
#if TIER_ONE
assert(next_instr->op.code == STORE_FAST);
next_oparg = next_instr->op.arg;
#if _Py_TIER2
// In JIT builds, we might have inserted an executor after this instruction,
// which breaks this super instruction.
if (next_instr->op.code == ENTER_EXECUTOR) {
_PyExecutorObject *exec = _PyFrame_GetCode(frame)->co_executors->executors[next_oparg];
next_oparg = exec->vm_data.oparg;
}
#endif
assert(next_instr->op.code == STORE_FAST || next_instr->op.code == ENTER_EXECUTOR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong as it will fail if the code is instrumented. You'll need to use _Py_GetBaseCodeUnit()

#else
next_oparg = (int)CURRENT_OPERAND0_16();
#endif
Expand Down
10 changes: 9 additions & 1 deletion Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading