aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/flowgraph.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-12-19 11:04:44 +0000
committerGitHub <noreply@github.com>2023-12-19 11:04:44 +0000
commite51b4009454939e3ee5f1bfaed45ce65689a71b8 (patch)
tree0933d9a4624dbb4f74a00ef5e1e4dfdcf7ab5327 /Python/flowgraph.c
parent76d757b38b414964546393bdccff31c1f8be3843 (diff)
downloadcpython-e51b4009454939e3ee5f1bfaed45ce65689a71b8.tar.gz
cpython-e51b4009454939e3ee5f1bfaed45ce65689a71b8.zip
gh-113054: Compiler no longer replaces a redundant jump with no line number by a NOP (#113139)
Diffstat (limited to 'Python/flowgraph.c')
-rw-r--r--Python/flowgraph.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index fe632082d5a..d2e3a7ae441 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -1110,7 +1110,10 @@ remove_redundant_jumps(cfg_builder *g) {
* of that jump. If it is, then the jump instruction is redundant and
* can be deleted.
*/
+
assert(no_empty_basic_blocks(g));
+
+ bool remove_empty_blocks = false;
for (basicblock *b = g->g_entryblock; b != NULL; b = b->b_next) {
cfg_instr *last = basicblock_last_instr(b);
assert(last != NULL);
@@ -1122,10 +1125,22 @@ remove_redundant_jumps(cfg_builder *g) {
}
if (last->i_target == b->b_next) {
assert(b->b_next->b_iused);
- INSTR_SET_OP0(last, NOP);
+ if (last->i_loc.lineno == NO_LOCATION.lineno) {
+ b->b_iused--;
+ if (b->b_iused == 0) {
+ remove_empty_blocks = true;
+ }
+ }
+ else {
+ INSTR_SET_OP0(last, NOP);
+ }
}
}
}
+ if (remove_empty_blocks) {
+ eliminate_empty_basic_blocks(g);
+ }
+ assert(no_empty_basic_blocks(g));
return SUCCESS;
}