gh-138714: Don't assume next block has instructions when propagating line numbers (#138770)
Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
This commit is contained in:
@@ -1615,6 +1615,17 @@ class TestSpecifics(unittest.TestCase):
|
|||||||
def f():
|
def f():
|
||||||
a if (1 if b else c) else d
|
a if (1 if b else c) else d
|
||||||
|
|
||||||
|
def test_lineno_propagation_empty_blocks(self):
|
||||||
|
# Smoke test. See gh-138714.
|
||||||
|
def f():
|
||||||
|
while name:
|
||||||
|
try:
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
1 if 1 else 1
|
||||||
|
|
||||||
def test_global_declaration_in_except_used_in_else(self):
|
def test_global_declaration_in_except_used_in_else(self):
|
||||||
# See gh-111123
|
# See gh-111123
|
||||||
code = textwrap.dedent("""\
|
code = textwrap.dedent("""\
|
||||||
|
|||||||
@@ -3591,8 +3591,19 @@ duplicate_exits_without_lineno(cfg_builder *g)
|
|||||||
* Also reduces the size of the line number table,
|
* Also reduces the size of the line number table,
|
||||||
* but has no impact on the generated line number events.
|
* but has no impact on the generated line number events.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
maybe_propagate_location(basicblock *b, int i, location loc)
|
||||||
|
{
|
||||||
|
assert(b->b_iused > i);
|
||||||
|
if (b->b_instr[i].i_loc.lineno == NO_LOCATION.lineno) {
|
||||||
|
b->b_instr[i].i_loc = loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
propagate_line_numbers(basicblock *entryblock) {
|
propagate_line_numbers(basicblock *entryblock)
|
||||||
|
{
|
||||||
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
|
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
|
||||||
cfg_instr *last = basicblock_last_instr(b);
|
cfg_instr *last = basicblock_last_instr(b);
|
||||||
if (last == NULL) {
|
if (last == NULL) {
|
||||||
@@ -3601,26 +3612,21 @@ propagate_line_numbers(basicblock *entryblock) {
|
|||||||
|
|
||||||
location prev_location = NO_LOCATION;
|
location prev_location = NO_LOCATION;
|
||||||
for (int i = 0; i < b->b_iused; i++) {
|
for (int i = 0; i < b->b_iused; i++) {
|
||||||
if (b->b_instr[i].i_loc.lineno == NO_LOCATION.lineno) {
|
maybe_propagate_location(b, i, prev_location);
|
||||||
b->b_instr[i].i_loc = prev_location;
|
prev_location = b->b_instr[i].i_loc;
|
||||||
}
|
|
||||||
else {
|
|
||||||
prev_location = b->b_instr[i].i_loc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (BB_HAS_FALLTHROUGH(b) && b->b_next->b_predecessors == 1) {
|
if (BB_HAS_FALLTHROUGH(b) && b->b_next->b_predecessors == 1) {
|
||||||
if (b->b_next->b_iused > 0) {
|
if (b->b_next->b_iused > 0) {
|
||||||
if (b->b_next->b_instr[0].i_loc.lineno == NO_LOCATION.lineno) {
|
maybe_propagate_location(b->b_next, 0, prev_location);
|
||||||
b->b_next->b_instr[0].i_loc = prev_location;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_jump(last)) {
|
if (is_jump(last)) {
|
||||||
basicblock *target = last->i_target;
|
basicblock *target = last->i_target;
|
||||||
|
while (target->b_iused == 0 && target->b_predecessors == 1) {
|
||||||
|
target = target->b_next;
|
||||||
|
}
|
||||||
if (target->b_predecessors == 1) {
|
if (target->b_predecessors == 1) {
|
||||||
if (target->b_instr[0].i_loc.lineno == NO_LOCATION.lineno) {
|
maybe_propagate_location(target, 0, prev_location);
|
||||||
target->b_instr[0].i_loc = prev_location;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user