diff options
author | Mark Shannon <mark@hotpy.org> | 2022-02-16 11:26:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 11:26:02 (GMT) |
commit | d4e4ef107a9fea257981d7701f023177b704a44f (patch) | |
tree | 7c61e39a35eb845bf1c0d4a982bdcbbd006ebeee /Python | |
parent | 3d407b931156bc3ee5ae131de2f2babad831ccb2 (diff) | |
download | cpython-d4e4ef107a9fea257981d7701f023177b704a44f.zip cpython-d4e4ef107a9fea257981d7701f023177b704a44f.tar.gz cpython-d4e4ef107a9fea257981d7701f023177b704a44f.tar.bz2 |
[3.10] bpo-46724: Use `JUMP_ABSOLUTE` for all backward jumps. (GH-31326) (GH-31354)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/compile.c | 31 | ||||
-rw-r--r-- | Python/importlib.h | 8 | ||||
-rw-r--r-- | Python/importlib_external.h | 8 | ||||
-rw-r--r-- | Python/importlib_zipimport.h | 8 |
4 files changed, 43 insertions, 12 deletions
diff --git a/Python/compile.c b/Python/compile.c index a7f62bb..1416eb1 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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() */ @@ -6702,6 +6704,31 @@ 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) { + 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) { basicblock *b; @@ -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); diff --git a/Python/importlib.h b/Python/importlib.h index ab3e69b..dd1a9f1 100644 --- a/Python/importlib.h +++ b/Python/importlib.h @@ -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, diff --git a/Python/importlib_external.h b/Python/importlib_external.h index 62e47b1..dcf5505 100644 --- a/Python/importlib_external.h +++ b/Python/importlib_external.h @@ -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, diff --git a/Python/importlib_zipimport.h b/Python/importlib_zipimport.h index 07c9dd5..3c47684 100644 --- a/Python/importlib_zipimport.h +++ b/Python/importlib_zipimport.h @@ -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, |