From: David Malcolm Date: Tue, 28 Nov 2017 19:24:35 +0000 (+0000) Subject: Reject fix-it hints for various awkward boundary cases (PR c/82050) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6df8934f6ad73b97181fc0a997b3eb8cd799b6a0;p=gcc.git Reject fix-it hints for various awkward boundary cases (PR c/82050) PR c/82050 reports a failed assertion deep within diagnostic_show_locus's code for printing fix-it hints. The root cause is a fix-it hint suggesting a textual replacement, where the affected column numbers straddle the LINE_MAP_MAX_COLUMN_NUMBER boundary, so that the start of the range has a column number, but the end of the range doesn't. The fix is to verify that the column numbers are sane when adding fix-it hints to a rich_location, rejecting fix-it hints where they are not. libcpp/ChangeLog: PR c/82050 * include/line-map.h (LINE_MAP_MAX_COLUMN_NUMBER): Move here. * line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): ...from here. (rich_location::maybe_add_fixit): Reject fix-it hints in which the start column exceeds the next column. From-SVN: r255214 --- diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 556373e77c5..2250b7716d2 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2017-11-28 David Malcolm + + PR c/82050 + * include/line-map.h (LINE_MAP_MAX_COLUMN_NUMBER): Move here. + * line-map.c (LINE_MAP_MAX_COLUMN_NUMBER): ...from here. + (rich_location::maybe_add_fixit): Reject fix-it hints in which + the start column exceeds the next column. + 2017-11-20 Eric Gallager PR preprocessor/81794 diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 8b7e5dcd0ae..11514845881 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -280,6 +280,11 @@ enum lc_reason worked example in libcpp/location-example.txt. */ typedef unsigned int source_location; +/* Do not track column numbers higher than this one. As a result, the + range of column_bits is [12, 18] (or 0 if column numbers are + disabled). */ +const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); + /* Do not pack ranges if locations get higher than this. If you change this, update: gcc.dg/plugin/location-overflow-test-*.c. */ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 0e5804b65bc..ac621e9585c 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -26,11 +26,6 @@ along with this program; see the file COPYING3. If not see #include "internal.h" #include "hashtab.h" -/* Do not track column numbers higher than this one. As a result, the - range of column_bits is [12, 18] (or 0 if column numbers are - disabled). */ -const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12); - /* Highest possible source location encoded within an ordinary or macro map. */ const source_location LINE_MAP_MAX_SOURCE_LOCATION = 0x70000000; @@ -2352,6 +2347,14 @@ rich_location::maybe_add_fixit (source_location start, stop_supporting_fixits (); return; } + /* The columns must be in the correct order. This can fail if the + endpoints straddle the boundary for which the linemap can represent + columns (PR c/82050). */ + if (exploc_start.column > exploc_next_loc.column) + { + stop_supporting_fixits (); + return; + } const char *newline = strchr (new_content, '\n'); if (newline)