summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-10-06 12:05:45 (GMT)
committerGitHub <noreply@github.com>2021-10-06 12:05:45 (GMT)
commitf6eafe18c004c55082de40d20cad084ef9dd3db7 (patch)
treeb5e0d2f185b2da5cf66f7cbd00c66b87937d46ba /Python/compile.c
parentc379bc5ec9012cf66424ef3d80612cf13ec51006 (diff)
downloadcpython-f6eafe18c004c55082de40d20cad084ef9dd3db7.zip
cpython-f6eafe18c004c55082de40d20cad084ef9dd3db7.tar.gz
cpython-f6eafe18c004c55082de40d20cad084ef9dd3db7.tar.bz2
Normalize jumps in compiler. All forward jumps to use JUMP_FORWARD. (GH-28755)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 694da29..2d82d6a 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -7221,6 +7221,26 @@ assemble_emit(struct assembler *a, struct instr *i)
}
static void
+normalize_jumps(struct assembler *a)
+{
+ for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
+ b->b_visited = 0;
+ }
+ for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
+ b->b_visited = 1;
+ if (b->b_iused == 0) {
+ continue;
+ }
+ struct instr *last = &b->b_instr[b->b_iused-1];
+ if (last->i_opcode == JUMP_ABSOLUTE &&
+ last->i_target->b_visited == 0
+ ) {
+ last->i_opcode = JUMP_FORWARD;
+ }
+ }
+}
+
+static void
assemble_jump_offsets(struct assembler *a, struct compiler *c)
{
basicblock *b;
@@ -7897,6 +7917,9 @@ assemble(struct compiler *c, int addNone)
clean_basic_block(b);
}
+ /* Order of basic blocks must have been determined by now */
+ normalize_jumps(&a);
+
/* Can't modify the bytecode after computing jump offsets. */
assemble_jump_offsets(&a, c);