mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
[3.10] bpo-46724: Use JUMP_ABSOLUTE
for all backward jumps. (GH-31326) (GH-31354)
This commit is contained in:
parent
3d407b9311
commit
d4e4ef107a
6 changed files with 47 additions and 14 deletions
|
@ -1044,7 +1044,7 @@ expected_opinfo_jumpy = [
|
|||
Instruction(opname='COMPARE_OP', opcode=107, arg=4, argval='>', argrepr='>', offset=34, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=21, argval=42, argrepr='to 42', offset=36, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=8, is_jump_target=False),
|
||||
Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=26, argval=52, argrepr='to 52', offset=40, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='JUMP_FORWARD', opcode=110, arg=5, argval=52, argrepr='to 52', offset=40, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=4, argval=8, argrepr='to 8', offset=42, starts_line=7, is_jump_target=True),
|
||||
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=44, starts_line=10, is_jump_target=True),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='I can haz else clause?', argrepr="'I can haz else clause?'", offset=46, starts_line=None, is_jump_target=False),
|
||||
|
@ -1069,7 +1069,7 @@ expected_opinfo_jumpy = [
|
|||
Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=84, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='COMPARE_OP', opcode=107, arg=0, argval='<', argrepr='<', offset=86, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=46, argval=92, argrepr='to 92', offset=88, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='JUMP_ABSOLUTE', opcode=113, arg=52, argval=104, argrepr='to 104', offset=90, starts_line=17, is_jump_target=False),
|
||||
Instruction(opname='JUMP_FORWARD', opcode=110, arg=6, argval=104, argrepr='to 104', offset=90, starts_line=17, is_jump_target=False),
|
||||
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=92, starts_line=11, is_jump_target=True),
|
||||
Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=28, argval=56, argrepr='to 56', offset=94, starts_line=None, is_jump_target=False),
|
||||
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=96, starts_line=19, is_jump_target=True),
|
||||
|
|
|
@ -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``.
|
|
@ -128,6 +128,8 @@ typedef struct basicblock_ {
|
|||
unsigned b_nofallthrough : 1;
|
||||
/* Basic block exits scope (it ends with a return or raise) */
|
||||
unsigned b_exit : 1;
|
||||
/* Used by compiler passes to mark whether they have visited a basic block. */
|
||||
unsigned b_visited : 1;
|
||||
/* depth of stack upon entry of block, computed by stackdepth() */
|
||||
int b_startdepth;
|
||||
/* instruction offset for block, computed by assemble_jump_offsets() */
|
||||
|
@ -6701,6 +6703,31 @@ assemble_emit(struct assembler *a, struct instr *i)
|
|||
return 1;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (last->i_target->b_visited == 0) {
|
||||
last->i_opcode = JUMP_FORWARD;
|
||||
}
|
||||
}
|
||||
if (last->i_opcode == JUMP_FORWARD) {
|
||||
if (last->i_target->b_visited == 1) {
|
||||
last->i_opcode = JUMP_ABSOLUTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
assemble_jump_offsets(struct assembler *a, struct compiler *c)
|
||||
{
|
||||
|
@ -7137,6 +7164,10 @@ assemble(struct compiler *c, int addNone)
|
|||
}
|
||||
propagate_line_numbers(&a);
|
||||
guarantee_lineno_for_exits(&a, c->u->u_firstlineno);
|
||||
|
||||
/* 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);
|
||||
|
||||
|
|
8
Python/importlib.h
generated
8
Python/importlib.h
generated
|
@ -782,8 +782,8 @@ const unsigned char _Py_M__importlib_bootstrap[] = {
|
|||
103,0,110,1,100,2,125,5,124,4,124,0,124,1,124,5,
|
||||
100,4,141,3,83,0,124,3,100,2,117,0,114,67,116,0,
|
||||
124,1,100,5,131,2,114,65,122,7,124,1,160,4,124,0,
|
||||
161,1,125,3,87,0,113,67,4,0,116,5,121,64,1,0,
|
||||
1,0,1,0,100,2,125,3,89,0,113,67,119,0,100,6,
|
||||
161,1,125,3,87,0,110,13,4,0,116,5,121,64,1,0,
|
||||
1,0,1,0,100,2,125,3,89,0,110,3,119,0,100,6,
|
||||
125,3,116,6,124,0,124,1,124,2,124,3,100,7,141,4,
|
||||
83,0,41,8,122,53,82,101,116,117,114,110,32,97,32,109,
|
||||
111,100,117,108,101,32,115,112,101,99,32,98,97,115,101,100,
|
||||
|
@ -812,9 +812,9 @@ const unsigned char _Py_M__importlib_bootstrap[] = {
|
|||
122,5,124,0,106,4,125,5,87,0,110,11,4,0,116,1,
|
||||
121,59,1,0,1,0,1,0,100,0,125,5,89,0,110,1,
|
||||
119,0,124,2,100,0,117,0,114,87,124,5,100,0,117,0,
|
||||
114,85,122,5,124,1,106,5,125,2,87,0,113,87,4,0,
|
||||
114,85,122,5,124,1,106,5,125,2,87,0,110,13,4,0,
|
||||
116,1,121,84,1,0,1,0,1,0,100,0,125,2,89,0,
|
||||
113,87,119,0,124,5,125,2,122,5,124,0,106,6,125,6,
|
||||
110,3,119,0,124,5,125,2,122,5,124,0,106,6,125,6,
|
||||
87,0,110,11,4,0,116,1,121,103,1,0,1,0,1,0,
|
||||
100,0,125,6,89,0,110,1,119,0,122,7,116,7,124,0,
|
||||
106,8,131,1,125,7,87,0,110,11,4,0,116,1,121,122,
|
||||
|
|
8
Python/importlib_external.h
generated
8
Python/importlib_external.h
generated
|
@ -977,8 +977,8 @@ const unsigned char _Py_M__importlib_bootstrap_external[] = {
|
|||
8,0,0,0,67,0,0,0,115,54,1,0,0,124,1,100,
|
||||
1,117,0,114,29,100,2,125,1,116,0,124,2,100,3,131,
|
||||
2,114,28,122,7,124,2,160,1,124,0,161,1,125,1,87,
|
||||
0,113,57,4,0,116,2,121,27,1,0,1,0,1,0,89,
|
||||
0,113,57,119,0,110,28,116,3,160,4,124,1,161,1,125,
|
||||
0,110,38,4,0,116,2,121,27,1,0,1,0,1,0,89,
|
||||
0,110,30,119,0,110,28,116,3,160,4,124,1,161,1,125,
|
||||
1,116,5,124,1,131,1,115,57,122,9,116,6,116,3,160,
|
||||
7,161,0,124,1,131,2,125,1,87,0,110,9,4,0,116,
|
||||
8,121,56,1,0,1,0,1,0,89,0,110,1,119,0,116,
|
||||
|
@ -986,11 +986,11 @@ const unsigned char _Py_M__importlib_bootstrap_external[] = {
|
|||
5,124,4,95,11,124,2,100,1,117,0,114,99,116,12,131,
|
||||
0,68,0,93,21,92,2,125,5,125,6,124,1,160,13,116,
|
||||
14,124,6,131,1,161,1,114,96,124,5,124,0,124,1,131,
|
||||
2,125,2,124,2,124,4,95,15,1,0,113,99,113,75,100,
|
||||
2,125,2,124,2,124,4,95,15,1,0,110,3,113,75,100,
|
||||
1,83,0,124,3,116,16,117,0,114,131,116,0,124,2,100,
|
||||
6,131,2,114,130,122,7,124,2,160,17,124,0,161,1,125,
|
||||
7,87,0,110,9,4,0,116,2,121,124,1,0,1,0,1,
|
||||
0,89,0,113,134,119,0,124,7,114,130,103,0,124,4,95,
|
||||
0,89,0,110,10,119,0,124,7,114,130,103,0,124,4,95,
|
||||
18,110,3,124,3,124,4,95,18,124,4,106,18,103,0,107,
|
||||
2,114,153,124,1,114,153,116,19,124,1,131,1,100,7,25,
|
||||
0,125,8,124,4,106,18,160,20,124,8,161,1,1,0,124,
|
||||
|
|
|
@ -130,7 +130,7 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
3,141,2,130,1,124,5,125,1,124,3,160,13,124,6,161,
|
||||
1,1,0,89,0,110,15,119,0,124,4,106,14,100,6,64,
|
||||
0,100,7,107,3,114,89,116,4,100,5,124,1,100,3,141,
|
||||
2,130,1,113,91,113,33,122,6,116,15,124,1,25,0,125,
|
||||
2,130,1,110,1,113,33,122,6,116,15,124,1,25,0,125,
|
||||
7,87,0,110,17,4,0,116,16,121,114,1,0,1,0,1,
|
||||
0,116,17,124,1,131,1,125,7,124,7,116,15,124,1,60,
|
||||
0,89,0,110,1,119,0,124,7,124,0,95,18,124,1,124,
|
||||
|
@ -653,7 +653,7 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
100,2,141,2,130,1,119,0,9,0,124,1,160,7,100,16,
|
||||
161,1,125,3,116,8,124,3,131,1,100,5,107,0,144,1,
|
||||
114,55,116,14,100,17,131,1,130,1,124,3,100,0,100,5,
|
||||
133,2,25,0,100,18,107,3,144,1,114,66,144,2,113,85,
|
||||
133,2,25,0,100,18,107,3,144,1,114,66,144,1,110,19,
|
||||
116,8,124,3,131,1,100,16,107,3,144,1,114,77,116,14,
|
||||
100,17,131,1,130,1,116,15,124,3,100,19,100,20,133,2,
|
||||
25,0,131,1,125,13,116,15,124,3,100,20,100,9,133,2,
|
||||
|
@ -1004,9 +1004,9 @@ const unsigned char _Py_M__zipimport[] = {
|
|||
1,0,1,0,89,0,113,9,119,0,124,8,100,4,25,0,
|
||||
125,9,116,8,124,0,106,4,124,8,131,2,125,10,100,0,
|
||||
125,11,124,5,114,91,122,10,116,9,124,0,124,9,124,7,
|
||||
124,1,124,10,131,5,125,11,87,0,113,96,4,0,116,10,
|
||||
124,1,124,10,131,5,125,11,87,0,110,25,4,0,116,10,
|
||||
121,90,1,0,125,12,1,0,122,8,124,12,125,3,87,0,
|
||||
89,0,100,0,125,12,126,12,113,96,100,0,125,12,126,12,
|
||||
89,0,100,0,125,12,126,12,110,10,100,0,125,12,126,12,
|
||||
119,1,119,0,116,11,124,9,124,10,131,2,125,11,124,11,
|
||||
100,0,117,0,114,101,113,9,124,8,100,4,25,0,125,9,
|
||||
124,11,124,6,124,9,102,3,2,0,1,0,83,0,124,3,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue