]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostic-show-locus.c: rework handling of multiple labels
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 30 Sep 2019 20:03:55 +0000 (20:03 +0000)
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 30 Sep 2019 20:03:55 +0000 (20:03 +0000)
commit9e2f4c7e20c5012a54e4b3864c6badb1a5176803
tree714cd83c7f54b55c831205be869d3c3dd488b5e5
parent489e786b57f12fa95899661bfe1ec3bacc5c5128
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@276371 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/diagnostic-show-locus.c