Skip to content

Commit 98022e0

Browse files
committed
Add guard for code object when projecting traces through calls
1 parent d484383 commit 98022e0

File tree

6 files changed

+121
-95
lines changed

6 files changed

+121
-95
lines changed

Include/internal/pycore_uop_ids.h

Lines changed: 96 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,10 @@ dummy_func(
42934293
DEOPT_IF(!((_PyExecutorObject *)executor)->vm_data.valid);
42944294
}
42954295

4296+
tier2 op(_GUARD_CODE, (version/2 -- )) {
4297+
DEOPT_IF(((PyCodeObject *)frame->f_executable)->co_version != version);
4298+
}
4299+
42964300
tier2 op(_FATAL_ERROR, (--)) {
42974301
assert(0);
42984302
Py_FatalError("Fatal error uop executed.");

Python/executor_cases.c.h

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,13 @@ translate_bytecode_to_trace(
893893
operand = 0;
894894
}
895895
ADD_TO_TRACE(uop, oparg, operand, target);
896+
/* We need to guard that the runtime code object is
897+
* the same one we are projecting into */
896898
code = new_code;
897899
func = new_func;
898900
instr = _PyCode_CODE(code);
901+
assert(code->co_version != 0);
902+
ADD_TO_TRACE(_GUARD_CODE, 0, code->co_version, 0);
899903
DPRINTF(2,
900904
"Continuing in %s (%s:%d) at byte offset %d\n",
901905
PyUnicode_AsUTF8(code->co_qualname),

Python/optimizer_cases.c.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)