aboutsummaryrefslogtreecommitdiff
path: root/libcpp/line-map.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2021-02-10 14:33:10 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2021-02-10 14:33:10 -0500
commit1f5c80883efce5242d892eb771ebb60830d20e0f (patch)
tree0f8f2b3c9af09149a8e0f0e4a5e28abe8b82674e /libcpp/line-map.c
parent0f39fb7b001df7cdba56cd5c572d0737667acd2c (diff)
downloadgcc-1f5c80883efce5242d892eb771ebb60830d20e0f.zip
gcc-1f5c80883efce5242d892eb771ebb60830d20e0f.tar.gz
gcc-1f5c80883efce5242d892eb771ebb60830d20e0f.tar.bz2
libcpp: fix ICE comparing macro locations without column info [PR96391]
PR preprocessor/96391 describes an ICE in the C++ frontend on: #define CONST const #define VOID void typedef CONST VOID *PCVOID; where the typedef line occurs after enough code has been compiled that location_t values are beyond LINE_MAP_MAX_LOCATION_WITH_COLS, and hence no column numbers are available. The issue occurs in linemap_compare_locations when comparing the locations of the "const" and "void" tokens. Upon resolving the LRK_MACRO_EXPANSION_POINT, both have the same location_t, the line of the "typedef" (with no column), and so the l0 == l1 clause is triggered, but they are not from the same macro expansion, leading first_map_in_common to return NULL and triggering the "abort" condition. This patch fixes the issue by checking when the two macro expansion point location_t values are equal that the value <= LINE_MAP_MAX_LOCATION_WITH_COLS and thus has column information, fixing the issue. gcc/testsuite/ChangeLog: PR preprocessor/96391 * g++.dg/plugin/location-overflow-test-pr96391.c: New test. * g++.dg/plugin/plugin.exp (plugin_test_list): Add it, using the location_overflow_plugin.c from gcc.dg/plugin. libcpp/ChangeLog: PR preprocessor/96391 * line-map.c (linemap_compare_locations): Require that the location be <= LINE_MAP_MAX_LOCATION_WITH_COLS when treating locations as coming from the same macro expansion.
Diffstat (limited to 'libcpp/line-map.c')
-rw-r--r--libcpp/line-map.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 2432cd5..cccacf2 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -1417,7 +1417,8 @@ linemap_compare_locations (line_maps *set,
if (l0 == l1
&& pre_virtual_p
- && post_virtual_p)
+ && post_virtual_p
+ && l0 <= LINE_MAP_MAX_LOCATION_WITH_COLS)
{
/* So pre and post represent two tokens that are present in a
same macro expansion. Let's see if the token for pre was