aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2021-03-02 15:46:06 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2021-03-02 15:46:06 -0500
commit41fbacdd10305654b1d10f887fa3f4677f9b8f34 (patch)
tree14f8aedff14c4fb3cb19cc7a922d12d79272eb2a /libcpp
parente7ca37649e4f322e7512c6d11813992c61b0a4b3 (diff)
downloadgcc-41fbacdd10305654b1d10f887fa3f4677f9b8f34.zip
gcc-41fbacdd10305654b1d10f887fa3f4677f9b8f34.tar.gz
gcc-41fbacdd10305654b1d10f887fa3f4677f9b8f34.tar.bz2
diagnostics: fix ICE on fix-it hints on very long lines [PR99323]
PR c/99323 describes an ICE due to a failed assertion deep inside the fix-it printing machinery, where the fix-it hints on one line have not been properly sorted in layout's constructor. The underlying issue occurs when multiple fix-it hints affect a line wider that LINE_MAP_MAX_COLUMN_NUMBER, where the location_t values for characters after that threshold fall back to having column zero. It's not meaningful to try to handle fix-it hints without column information, so this patch rejects them as they are added to the rich_location, falling back to the "no fix-it hints on this diagnostic" case, fixing the crash. gcc/ChangeLog: PR c/99323 * diagnostic-show-locus.c (selftest::test_one_liner_many_fixits_2): Fix accidental usage of column 0. gcc/testsuite/ChangeLog: PR c/99323 * gcc.dg/pr99323-1.c: New test. * gcc.dg/pr99323-2.c: New test. libcpp/ChangeLog: PR c/99323 * line-map.c (rich_location::maybe_add_fixit): Reject fix-it hints at column 0.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/line-map.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index ccabd51..a003af8 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -2431,6 +2431,14 @@ rich_location::maybe_add_fixit (location_t start,
stop_supporting_fixits ();
return;
}
+ /* If we have very long lines, tokens will eventually fall back to
+ having column == 0.
+ We can't handle fix-it hints that use such locations. */
+ if (exploc_start.column == 0 || exploc_next_loc.column == 0)
+ {
+ stop_supporting_fixits ();
+ return;
+ }
const char *newline = strchr (new_content, '\n');
if (newline)