From fac047752090421c3d5a38aad937b61513864b6c Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 3 Mar 2022 14:30:12 -0800 Subject: [PATCH 1/2] Handle cache entries correctly in BINARY_OP --- Python/ceval.c | 5 +++-- Python/specialize.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index e47e0521ea9413..e929b89bf32708 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2042,8 +2042,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP); DEOPT_IF(Py_TYPE(right) != Py_TYPE(left), BINARY_OP); DEOPT_IF(Py_REFCNT(left) != 2, BINARY_OP); - int next_oparg = _Py_OPARG(*next_instr); - assert(_Py_OPCODE(*next_instr) == STORE_FAST); + _Py_CODEUNIT true_next = next_instr[INLINE_CACHE_ENTRIES_BINARY_OP]; + int next_oparg = _Py_OPARG(true_next); + assert(_Py_OPCODE(true_next) == STORE_FAST); /* In the common case, there are 2 references to the value * stored in 'variable' when the v = v + ... is performed: one * on the value stack (in 'v') and one still stored in the diff --git a/Python/specialize.c b/Python/specialize.c index 5486b5b1f65dc9..81d542a3f83ce9 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1949,7 +1949,8 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr, break; } if (PyUnicode_CheckExact(lhs)) { - if (_Py_OPCODE(instr[1]) == STORE_FAST && Py_REFCNT(lhs) == 2) { + _Py_CODEUNIT next = instr[INLINE_CACHE_ENTRIES_BINARY_OP + 1]; + if (_Py_OPCODE(next) == STORE_FAST && Py_REFCNT(lhs) == 2) { *instr = _Py_MAKECODEUNIT(BINARY_OP_INPLACE_ADD_UNICODE, oparg); goto success; From f5d3c19ff0dae53969b5720a015fcd308de478ae Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Thu, 3 Mar 2022 14:32:01 -0800 Subject: [PATCH 2/2] blurb add --- .../Core and Builtins/2022-03-03-14-31-53.bpo-46841.agf-3X.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-03-03-14-31-53.bpo-46841.agf-3X.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-03-03-14-31-53.bpo-46841.agf-3X.rst b/Misc/NEWS.d/next/Core and Builtins/2022-03-03-14-31-53.bpo-46841.agf-3X.rst new file mode 100644 index 00000000000000..690293e97dcc37 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-03-03-14-31-53.bpo-46841.agf-3X.rst @@ -0,0 +1,2 @@ +Fix incorrect handling of inline cache entries when specializing +:opcode:`BINARY_OP`.