Commit 7168133a by David Malcolm Committed by David Malcolm

PR preprocessor/69985: fix ICE with long lines in -Wformat

gcc/testsuite/ChangeLog:
	PR preprocessor/69985
	* gcc.dg/cpp/pr69985.c: New test case.

libcpp/ChangeLog:
	PR preprocessor/69985
	(linemap_position_for_loc_and_offset): Rename param from "offset"
	to "column_offset".  Right-shift the column_offset by m_range_bits
	of the pertinent ordinary map whenever offsetting a
	source_location.  For clarity, offset the column by the column
	offset, rather than the other way around.

From-SVN: r233836
parent f3c7a945
2016-02-29 David Malcolm <dmalcolm@redhat.com>
PR preprocessor/69985
* gcc.dg/cpp/pr69985.c: New test case.
2016-02-29 Jeff Law <law@redhat.com> 2016-02-29 Jeff Law <law@redhat.com>
PR tree-optimization/70005 PR tree-optimization/70005
......
/* { dg-options "-Wformat" } */
extern int printf (const char *__restrict __format, ...);
void test (void)
{
/* A very long line, so that we start a new line map. */
printf ("%llu01233456789012334567890123345678901233456789012334567890123345678901233456789012334567890123345678901233456789012334567890123345678901233456789"); /* { dg-warning "15: format .%llu. expects a matching" } */
}
2016-02-29 David Malcolm <dmalcolm@redhat.com>
PR preprocessor/69985
(linemap_position_for_loc_and_offset): Rename param from "offset"
to "column_offset". Right-shift the column_offset by m_range_bits
of the pertinent ordinary map whenever offsetting a
source_location. For clarity, offset the column by the column
offset, rather than the other way around.
2016-02-23 David Malcolm <dmalcolm@redhat.com> 2016-02-23 David Malcolm <dmalcolm@redhat.com>
PR preprocessor/69126 PR preprocessor/69126
......
...@@ -864,13 +864,13 @@ linemap_position_for_line_and_column (line_maps *set, ...@@ -864,13 +864,13 @@ linemap_position_for_line_and_column (line_maps *set,
} }
/* Encode and return a source_location starting from location LOC and /* Encode and return a source_location starting from location LOC and
shifting it by OFFSET columns. This function does not support shifting it by COLUMN_OFFSET columns. This function does not support
virtual locations. */ virtual locations. */
source_location source_location
linemap_position_for_loc_and_offset (struct line_maps *set, linemap_position_for_loc_and_offset (struct line_maps *set,
source_location loc, source_location loc,
unsigned int offset) unsigned int column_offset)
{ {
const line_map_ordinary * map = NULL; const line_map_ordinary * map = NULL;
...@@ -882,7 +882,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set, ...@@ -882,7 +882,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
(!linemap_location_from_macro_expansion_p (set, loc))) (!linemap_location_from_macro_expansion_p (set, loc)))
return loc; return loc;
if (offset == 0 if (column_offset == 0
/* Adding an offset to a reserved location (like /* Adding an offset to a reserved location (like
UNKNOWN_LOCATION for the C/C++ FEs) does not really make UNKNOWN_LOCATION for the C/C++ FEs) does not really make
sense. So let's leave the location intact in that case. */ sense. So let's leave the location intact in that case. */
...@@ -894,7 +894,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set, ...@@ -894,7 +894,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
/* The new location (loc + offset) should be higher than the first /* The new location (loc + offset) should be higher than the first
location encoded by MAP. This can fail if the line information location encoded by MAP. This can fail if the line information
is messed up because of line directives (see PR66415). */ is messed up because of line directives (see PR66415). */
if (MAP_START_LOCATION (map) >= loc + offset) if (MAP_START_LOCATION (map) >= loc + (column_offset << map->m_range_bits))
return loc; return loc;
linenum_type line = SOURCE_LINE (map, loc); linenum_type line = SOURCE_LINE (map, loc);
...@@ -905,7 +905,8 @@ linemap_position_for_loc_and_offset (struct line_maps *set, ...@@ -905,7 +905,8 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
the next line map of the set. Otherwise, we try to encode the the next line map of the set. Otherwise, we try to encode the
location in the next map. */ location in the next map. */
while (map != LINEMAPS_LAST_ORDINARY_MAP (set) while (map != LINEMAPS_LAST_ORDINARY_MAP (set)
&& loc + offset >= MAP_START_LOCATION (&map[1])) && (loc + (column_offset << map->m_range_bits)
>= MAP_START_LOCATION (&map[1])))
{ {
map = &map[1]; map = &map[1];
/* If the next map starts in a higher line, we cannot encode the /* If the next map starts in a higher line, we cannot encode the
...@@ -914,12 +915,12 @@ linemap_position_for_loc_and_offset (struct line_maps *set, ...@@ -914,12 +915,12 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
return loc; return loc;
} }
offset += column; column += column_offset;
if (linemap_assert_fails (offset < (1u << map->m_column_and_range_bits))) if (linemap_assert_fails (column < (1u << map->m_column_and_range_bits)))
return loc; return loc;
source_location r = source_location r =
linemap_position_for_line_and_column (set, map, line, offset); linemap_position_for_line_and_column (set, map, line, column);
if (linemap_assert_fails (r <= set->highest_location) if (linemap_assert_fails (r <= set->highest_location)
|| linemap_assert_fails (map == linemap_lookup (set, r))) || linemap_assert_fails (map == linemap_lookup (set, r)))
return loc; return loc;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment