diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2022-07-22 18:56:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-22 18:56:10 (GMT) |
commit | 5a48ab01e93c92594eac777c499d1e728ddf1f7e (patch) | |
tree | 5290c6976cfbacf7664ef221c3c2057cff11faf7 /Python | |
parent | e99496e1c20253d0d2e2e016509cd9c2fa24dd85 (diff) | |
download | cpython-5a48ab01e93c92594eac777c499d1e728ddf1f7e.zip cpython-5a48ab01e93c92594eac777c499d1e728ddf1f7e.tar.gz cpython-5a48ab01e93c92594eac777c499d1e728ddf1f7e.tar.bz2 |
[3.11] GH-95113: Don't use EXTENDED_ARG_QUICK in unquickened code (GH-95121) (GH-95143)
(cherry picked from commit e402b26b7fb953a2f0c17a0044bb6d6cbd726e54)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 8 | ||||
-rw-r--r-- | Python/compile.c | 6 | ||||
-rw-r--r-- | Python/specialize.c | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index c69ea21..d40bf27 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5590,8 +5590,16 @@ handle_eval_breaker: assert(oparg); oparg <<= 8; oparg |= _Py_OPARG(*next_instr); + // We might be tracing. To avoid breaking tracing guarantees in + // quickened instructions, always deoptimize the next opcode: opcode = _PyOpcode_Deopt[_Py_OPCODE(*next_instr)]; PRE_DISPATCH_GOTO(); + // CPython hasn't traced the following instruction historically + // (DO_TRACING would clobber our extended oparg anyways), so just + // skip our usual cframe.use_tracing check before dispatch. Also, + // make sure the next instruction isn't a RESUME, since that needs + // to trace properly (and shouldn't have an extended arg anyways): + assert(opcode != RESUME); DISPATCH_GOTO(); } diff --git a/Python/compile.c b/Python/compile.c index e8acd85..8895ac7 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -211,13 +211,13 @@ write_instr(_Py_CODEUNIT *codestr, struct instr *instruction, int ilen) int caches = _PyOpcode_Caches[opcode]; switch (ilen - caches) { case 4: - *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG_QUICK, (oparg >> 24) & 0xFF); + *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG, (oparg >> 24) & 0xFF); /* fall through */ case 3: - *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG_QUICK, (oparg >> 16) & 0xFF); + *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG, (oparg >> 16) & 0xFF); /* fall through */ case 2: - *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG_QUICK, (oparg >> 8) & 0xFF); + *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG, (oparg >> 8) & 0xFF); /* fall through */ case 1: *codestr++ = _Py_MAKECODEUNIT(opcode, oparg & 0xFF); diff --git a/Python/specialize.c b/Python/specialize.c index 5f2c6b3..b318cb5 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -275,6 +275,9 @@ _PyCode_Quicken(PyCodeObject *code) else { assert(!_PyOpcode_Caches[opcode]); switch (opcode) { + case EXTENDED_ARG: + _Py_SET_OPCODE(instructions[i], EXTENDED_ARG_QUICK); + break; case JUMP_BACKWARD: _Py_SET_OPCODE(instructions[i], JUMP_BACKWARD_QUICK); break; |