mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
gh-115480: Type propagate _BINARY_OP_ADD_UNICODE (GH-115710)
This commit is contained in:
parent
b5949eac62
commit
ff96b81d78
3 changed files with 66 additions and 8 deletions
|
@ -254,6 +254,22 @@ dummy_func(void) {
|
|||
}
|
||||
}
|
||||
|
||||
op(_BINARY_OP_ADD_UNICODE, (left, right -- res)) {
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
|
||||
PyObject *temp = PyUnicode_Concat(sym_get_const(left), sym_get_const(right));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyUnicode_Type));
|
||||
}
|
||||
}
|
||||
|
||||
op(_TO_BOOL, (value -- res)) {
|
||||
(void)value;
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
|
|
19
Python/optimizer_cases.c.h
generated
19
Python/optimizer_cases.c.h
generated
|
@ -446,9 +446,24 @@
|
|||
}
|
||||
|
||||
case _BINARY_OP_ADD_UNICODE: {
|
||||
_Py_UopsSymbol *right;
|
||||
_Py_UopsSymbol *left;
|
||||
_Py_UopsSymbol *res;
|
||||
res = sym_new_unknown(ctx);
|
||||
if (res == NULL) goto out_of_space;
|
||||
right = stack_pointer[-1];
|
||||
left = stack_pointer[-2];
|
||||
if (sym_is_const(left) && sym_is_const(right) &&
|
||||
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
|
||||
PyObject *temp = PyUnicode_Concat(sym_get_const(left), sym_get_const(right));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
OUT_OF_SPACE_IF_NULL(res);
|
||||
}
|
||||
else {
|
||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyUnicode_Type));
|
||||
}
|
||||
stack_pointer[-2] = res;
|
||||
stack_pointer += -1;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue