mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-37213: Handle negative line deltas correctly in the peephole optimizer (GH-13969)
The peephole optimizer was not optimizing correctly bytecode after negative deltas were introduced. This is due to the fact that some special values (255) were being searched for in both instruction pointer delta and line number deltas.
(cherry picked from commit 3498c642f4
)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
parent
ec3839a215
commit
5282b3b1d2
6 changed files with 4234 additions and 4150 deletions
|
@ -250,12 +250,16 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
|
|||
lnotab = (unsigned char*)PyBytes_AS_STRING(lnotab_obj);
|
||||
tabsiz = PyBytes_GET_SIZE(lnotab_obj);
|
||||
assert(tabsiz == 0 || Py_REFCNT(lnotab_obj) == 1);
|
||||
if (memchr(lnotab, 255, tabsiz) != NULL) {
|
||||
/* 255 value are used for multibyte bytecode instructions */
|
||||
goto exitUnchanged;
|
||||
|
||||
/* Don't optimize if lnotab contains instruction pointer delta larger
|
||||
than +255 (encoded as multiple bytes), just to keep the peephole optimizer
|
||||
simple. The optimizer leaves line number deltas unchanged. */
|
||||
|
||||
for (j = 0; j < tabsiz; j += 2) {
|
||||
if (lnotab[j] == 255) {
|
||||
goto exitUnchanged;
|
||||
}
|
||||
}
|
||||
/* Note: -128 and 127 special values for line number delta are ok,
|
||||
the peephole optimizer doesn't modify line numbers. */
|
||||
|
||||
assert(PyBytes_Check(code));
|
||||
Py_ssize_t codesize = PyBytes_GET_SIZE(code);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue