gh-148374: Fix a bug in _Py_uop_sym_get_type (GH-148375)

This commit is contained in:
Sacul 2026-04-11 23:03:13 +08:00 committed by GitHub
parent a059e85866
commit 83f33dccf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -783,6 +783,7 @@ _Py_uop_sym_get_type(JitOptRef ref)
case JIT_SYM_NON_NULL_TAG:
case JIT_SYM_UNKNOWN_TAG:
case JIT_SYM_RECORDED_TYPE_TAG:
case JIT_SYM_RECORDED_GEN_FUNC_TAG:
return NULL;
case JIT_SYM_RECORDED_VALUE_TAG:
if (sym->recorded_value.known_type) {
@ -804,8 +805,6 @@ _Py_uop_sym_get_type(JitOptRef ref)
return &PyBool_Type;
case JIT_SYM_COMPACT_INT:
return &PyLong_Type;
case JIT_SYM_RECORDED_GEN_FUNC_TAG:
return &PyGen_Type;
}
Py_UNREACHABLE();
}
@ -830,7 +829,7 @@ _Py_uop_sym_get_probable_type(JitOptRef ref)
case JIT_SYM_KNOWN_VALUE_TAG:
return _Py_uop_sym_get_type(ref);
case JIT_SYM_RECORDED_GEN_FUNC_TAG:
return NULL;
return &PyGen_Type;
case JIT_SYM_RECORDED_VALUE_TAG:
return Py_TYPE(sym->recorded_value.value);
case JIT_SYM_RECORDED_TYPE_TAG:
@ -2211,7 +2210,8 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
/* Test that recorded type aren't treated as known values*/
JitOptRef rg1 = _Py_uop_sym_new_unknown(ctx);
_Py_uop_sym_set_recorded_gen_func(ctx, rg1, func);
TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator");
TEST_PREDICATE(!_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg1) == &PyGen_Type, "recorded gen func not treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg1) == NULL, "recorded gen func is treated as known value");
/* Test that setting type narrows correctly */
@ -2219,13 +2219,15 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
JitOptRef rg2 = _Py_uop_sym_new_unknown(ctx);
_Py_uop_sym_set_recorded_gen_func(ctx, rg2, func);
_Py_uop_sym_set_type(ctx, rg2, &PyGen_Type);
TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator");
TEST_PREDICATE(!_Py_uop_sym_matches_type(rg2, &PyGen_Type), "recorded gen func treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg2) == &PyGen_Type, "recorded gen func not treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg2) == NULL, "known type is treated as known value");
JitOptRef rg3 = _Py_uop_sym_new_unknown(ctx);
_Py_uop_sym_set_recorded_gen_func(ctx, rg3, func);
_Py_uop_sym_set_type_version(ctx, rg3, PyGen_Type.tp_version_tag);
TEST_PREDICATE(_Py_uop_sym_matches_type(rg1, &PyGen_Type), "recorded gen func not treated as generator");
TEST_PREDICATE(!_Py_uop_sym_matches_type(rg3, &PyGen_Type), "recorded gen func treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_probable_type(rg3) == &PyGen_Type, "recorded gen func not treated as generator");
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, rg3) == NULL, "recorded value with type is treated as known");
/* Test contradictions */