aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer_bytecodes.c
diff options
context:
space:
mode:
authorKen Jin <kenjin@python.org>2024-03-02 03:40:04 +0800
committerGitHub <noreply@github.com>2024-03-02 03:40:04 +0800
commitff96b81d78c4a52fb1eb8384300af3dd0dd2db0d (patch)
treea3469d8fccfcdc41e7bda006c0e61d2d24f4226c /Python/optimizer_bytecodes.c
parentb5949eac6220ee8002971b5e7026432ac7990c74 (diff)
downloadcpython-ff96b81d78c4a52fb1eb8384300af3dd0dd2db0d.tar.gz
cpython-ff96b81d78c4a52fb1eb8384300af3dd0dd2db0d.zip
gh-115480: Type propagate _BINARY_OP_ADD_UNICODE (GH-115710)
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r--Python/optimizer_bytecodes.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index 2b47381ec76..786d884fc5a 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -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);