preprocessor: Fix ICE with too long line in fmtwarn [PR96935]
authorMarek Polacek <polacek@redhat.com>
Wed, 16 Sep 2020 13:27:29 +0000 (09:27 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 16 Sep 2020 19:29:49 +0000 (15:29 -0400)
commit31dd5cd6344bfbbe122fb512993b128e11236d35
tree4e4ccd17c40a49f3f0ffcb0db94f3fc8b1eed84d
parent8b75204b27cb2a296ac329d48918992b4053c61e
preprocessor: Fix ICE with too long line in fmtwarn [PR96935]

Here we ICE in char_span::subspan because the offset it gets is -1.
It's -1 because get_substring_ranges_for_loc gets a location whose
column was 0.  That only happens in testcases like the attached where
we're dealing with extremely long lines (at least 4065 chars it seems).
This does happen in practice, though, so it's not just a theoretical
problem (e.g. when building the SU2 suite).

Fixed by checking that the column get_substring_ranges_for_loc gets is
sane, akin to other checks in that function.

gcc/ChangeLog:

PR preprocessor/96935
* input.c (get_substring_ranges_for_loc): Return if start.column
is less than 1.

gcc/testsuite/ChangeLog:

PR preprocessor/96935
* gcc.dg/format/pr96935.c: New test.
gcc/input.c
gcc/testsuite/gcc.dg/format/pr96935.c [new file with mode: 0644]