aboutsummaryrefslogtreecommitdiff
path: root/libcpp/line-map.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-06-14 17:37:43 -0400
committerJason Merrill <jason@redhat.com>2021-06-16 11:41:08 -0400
commit9e64426dae129cca5b62355ef6c5a3bd6137e830 (patch)
tree743aef1e7b4ba903473889568e8f79aedd136b35 /libcpp/line-map.c
parentdd835ec24be9b1a89c6b0c78673de88c81a23966 (diff)
downloadgcc-9e64426dae129cca5b62355ef6c5a3bd6137e830.zip
gcc-9e64426dae129cca5b62355ef6c5a3bd6137e830.tar.gz
gcc-9e64426dae129cca5b62355ef6c5a3bd6137e830.tar.bz2
libcpp: location comparison within macro [PR100796]
The patch for 96391 changed linemap_compare_locations to give up on comparing locations from macro expansions if we don't have column information. But in this testcase, the BOILERPLATE macro is multiple lines long, so we do want to compare locations within the macro. So this patch moves the LINE_MAP_MAX_LOCATION_WITH_COLS check inside the block, to use it for failing gracefully. PR c++/100796 PR preprocessor/96391 libcpp/ChangeLog: * line-map.c (linemap_compare_locations): Only use comparison with LINE_MAP_MAX_LOCATION_WITH_COLS to avoid abort. gcc/testsuite/ChangeLog: * g++.dg/plugin/location-overflow-test-pr100796.c: New test. * g++.dg/plugin/plugin.exp: Run it.
Diffstat (limited to 'libcpp/line-map.c')
-rw-r--r--libcpp/line-map.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index a03d676..1a6902a 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -1421,23 +1421,25 @@ linemap_compare_locations (line_maps *set,
if (l0 == l1
&& pre_virtual_p
- && post_virtual_p
- && l0 <= LINE_MAP_MAX_LOCATION_WITH_COLS)
+ && post_virtual_p)
{
/* So pre and post represent two tokens that are present in a
same macro expansion. Let's see if the token for pre was
before the token for post in that expansion. */
- unsigned i0, i1;
const struct line_map *map =
first_map_in_common (set, pre, post, &l0, &l1);
if (map == NULL)
- /* This should not be possible. */
- abort ();
-
- i0 = l0 - MAP_START_LOCATION (map);
- i1 = l1 - MAP_START_LOCATION (map);
- return i1 - i0;
+ /* This should not be possible while we have column information, but if
+ we don't, the tokens could be from separate macro expansions on the
+ same line. */
+ gcc_assert (l0 > LINE_MAP_MAX_LOCATION_WITH_COLS);
+ else
+ {
+ unsigned i0 = l0 - MAP_START_LOCATION (map);
+ unsigned i1 = l1 - MAP_START_LOCATION (map);
+ return i1 - i0;
+ }
}
if (IS_ADHOC_LOC (l0))