diff options
author | Ken Jin <kenjin@python.org> | 2024-03-01 19:40:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-01 19:40:04 (GMT) |
commit | ff96b81d78c4a52fb1eb8384300af3dd0dd2db0d (patch) | |
tree | a3469d8fccfcdc41e7bda006c0e61d2d24f4226c /Python/optimizer_cases.c.h | |
parent | b5949eac6220ee8002971b5e7026432ac7990c74 (diff) | |
download | cpython-ff96b81d78c4a52fb1eb8384300af3dd0dd2db0d.zip cpython-ff96b81d78c4a52fb1eb8384300af3dd0dd2db0d.tar.gz cpython-ff96b81d78c4a52fb1eb8384300af3dd0dd2db0d.tar.bz2 |
gh-115480: Type propagate _BINARY_OP_ADD_UNICODE (GH-115710)
Diffstat (limited to 'Python/optimizer_cases.c.h')
-rw-r--r-- | Python/optimizer_cases.c.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 9d7ebb8..6d3488f 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -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; |