mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
[3.14] gh-135608: Add a null check for attribute promotion to fix a JIT crash (GH-135613) (#135739)
gh-135608: Add a null check for attribute promotion to fix a JIT crash (GH-135613) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
This commit is contained in:
parent
203753b4bb
commit
60fc42c169
5 changed files with 48 additions and 2 deletions
|
@ -1942,6 +1942,36 @@ class TestUopsOptimization(unittest.TestCase):
|
|||
self.assertNotIn("_COMPARE_OP_INT", uops)
|
||||
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
|
||||
|
||||
def test_attr_promotion_failure(self):
|
||||
# We're not testing for any specific uops here, just
|
||||
# testing it doesn't crash.
|
||||
script_helper.assert_python_ok('-c', textwrap.dedent("""
|
||||
import _testinternalcapi
|
||||
import _opcode
|
||||
import email
|
||||
|
||||
def get_first_executor(func):
|
||||
code = func.__code__
|
||||
co_code = code.co_code
|
||||
for i in range(0, len(co_code), 2):
|
||||
try:
|
||||
return _opcode.get_executor(code, i)
|
||||
except ValueError:
|
||||
pass
|
||||
return None
|
||||
|
||||
def testfunc(n):
|
||||
for _ in range(n):
|
||||
email.jit_testing = None
|
||||
prompt = email.jit_testing
|
||||
del email.jit_testing
|
||||
|
||||
|
||||
testfunc(_testinternalcapi.TIER2_THRESHOLD)
|
||||
ex = get_first_executor(testfunc)
|
||||
assert ex is not None
|
||||
"""))
|
||||
|
||||
|
||||
def global_identity(x):
|
||||
return x
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix a crash in the JIT involving attributes of modules.
|
|
@ -103,6 +103,10 @@ convert_global_to_const(_PyUOpInstruction *inst, PyObject *obj, bool pop)
|
|||
if ((int)index >= dict->ma_keys->dk_nentries) {
|
||||
return NULL;
|
||||
}
|
||||
PyDictKeysObject *keys = dict->ma_keys;
|
||||
if (keys->dk_version != inst->operand0) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *res = entries[index].me_value;
|
||||
if (res == NULL) {
|
||||
return NULL;
|
||||
|
|
|
@ -580,7 +580,13 @@ dummy_func(void) {
|
|||
PyDict_Watch(GLOBALS_WATCHER_ID, dict);
|
||||
_Py_BloomFilter_Add(dependencies, dict);
|
||||
PyObject *res = convert_global_to_const(this_instr, dict, true);
|
||||
attr = sym_new_const(ctx, res);
|
||||
if (res == NULL) {
|
||||
attr = sym_new_not_null(ctx);
|
||||
}
|
||||
else {
|
||||
attr = sym_new_const(ctx, res);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
Python/optimizer_cases.c.h
generated
7
Python/optimizer_cases.c.h
generated
|
@ -1235,7 +1235,12 @@
|
|||
PyDict_Watch(GLOBALS_WATCHER_ID, dict);
|
||||
_Py_BloomFilter_Add(dependencies, dict);
|
||||
PyObject *res = convert_global_to_const(this_instr, dict, true);
|
||||
attr = sym_new_const(ctx, res);
|
||||
if (res == NULL) {
|
||||
attr = sym_new_not_null(ctx);
|
||||
}
|
||||
else {
|
||||
attr = sym_new_const(ctx, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue