diagnostic-show-locus.c: rework handling of multiple labels
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 30 Sep 2019 20:03:55 +0000 (20:03 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Mon, 30 Sep 2019 20:03:55 +0000 (20:03 +0000)
commit5a05b737e1b626f92ee968f6e32715bf955dae54
tree714cd83c7f54b55c831205be869d3c3dd488b5e5
parent2f00786128f190a4ad7a0819a84026cd8be19ad4
diagnostic-show-locus.c: rework handling of multiple labels

This patch improves the handling of large numbers of labels within a
rich_location: previously, overlapping labels could lead to an assertion
failure within layout::print_any_labels.  Also, the labels were printed
in reverse order of insertion into the rich_location.

This patch moves the determination of whether a vertical bar should
be printed for a line_label into the
  'Figure out how many "label lines" we need, and which
   one each label is printed in.'
step of layout::print_any_labels, rather than doing it as the lines
are printed.  It also flips the sort order, so that labels at the
same line/column are printed in order of insertion into the
rich_location.

I haven't run into these issues with our existing diagnostics, but it
affects a patch kit I'm working on that makes more extensive use of
labels.

gcc/ChangeLog:
* diagnostic-show-locus.c (line_label::line_label): Initialize
m_has_vbar.
(line_label::comparator): Reverse the sort order by m_state_idx,
so that when the list is walked backwards the labels appear in
order of insertion into the rich_location.
(line_label::m_has_vbar): New field.
(layout::print_any_labels): When dealing with multiple labels at
the same line and column, only print vertical bars for the one
with the highest label_line.
(selftest::test_one_liner_labels): Update test for multiple labels
to expect the labels to be in the order of insertion into the
rich_location.  Add a test for many such labels, where the column
numbers are out-of-order relative to the insertion order.

From-SVN: r276371
gcc/ChangeLog
gcc/diagnostic-show-locus.c