From 62303c16a52aaba51c24f14e68dea178e5c16fa8 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Tue, 15 Feb 2022 09:35:16 +0000 Subject: [PATCH] bpo-46724: Use `JUMP_ABSOLUTE` for all backward jumps. (GH-31326) (cherry picked from commit 3be1a443ca8e7d4ba85f95b78df5c4122cae9ede) --- .../2022-02-14-14-44-06.bpo-46724.jym_K6.rst | 2 ++ Python/compile.c | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-02-14-14-44-06.bpo-46724.jym_K6.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-02-14-14-44-06.bpo-46724.jym_K6.rst b/Misc/NEWS.d/next/Core and Builtins/2022-02-14-14-44-06.bpo-46724.jym_K6.rst new file mode 100644 index 00000000000000..7324182677abfd --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-02-14-14-44-06.bpo-46724.jym_K6.rst @@ -0,0 +1,2 @@ +Make sure that all backwards jumps use the ``JUMP_ABSOLUTE`` instruction, rather +than ``JUMP_FORWARD`` with an argument of ``(2**32)+offset``. diff --git a/Python/compile.c b/Python/compile.c index a7f62bbcbb33e4..a8ace396b38484 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -6702,6 +6702,11 @@ assemble_emit(struct assembler *a, struct instr *i) } static void + if (last->i_opcode == JUMP_FORWARD) { + if (last->i_target->b_visited == 1) { + last->i_opcode = JUMP_ABSOLUTE; + } + } assemble_jump_offsets(struct assembler *a, struct compiler *c) { basicblock *b;