gh-109889: fix compiler's redundant NOP detection to look past NOPs with no lineno when looking for the next instruction's lineno (#109987)

This commit is contained in:
Irit Katriel 2023-09-28 20:33:28 +01:00 committed by GitHub
parent b14f0ab51c
commit f580edcc6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -1278,6 +1278,11 @@ class TestSpecifics(unittest.TestCase):
while x:
0 if 1 else 0
def test_remove_redundant_nop_edge_case(self):
# See gh-109889
def f():
a if (1 if b else c) else d
@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):
# Ensure that compiled code snippets have correct line and column numbers

View File

@ -0,0 +1,2 @@
Fix the compiler's redundant NOP detection algorithm to skip over NOPs with
no line number when looking for the next instruction's lineno.

View File

@ -1017,7 +1017,17 @@ remove_redundant_nops(basicblock *bb) {
}
/* or if last instruction in BB and next BB has same line number */
if (next) {
if (lineno == next->b_instr[0].i_loc.lineno) {
location next_loc = NO_LOCATION;
for (int next_i=0; next_i < next->b_iused; next_i++) {
cfg_instr *instr = &next->b_instr[next_i];
if (instr->i_opcode == NOP && instr->i_loc.lineno == NO_LOCATION.lineno) {
/* Skip over NOPs without location, they will be removed */
continue;
}
next_loc = instr->i_loc;
break;
}
if (lineno == next_loc.lineno) {
continue;
}
}