diff options
author | Nathan Sidwell <nathan@acm.org> | 2021-02-24 12:32:23 -0800 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2021-02-24 12:46:09 -0800 |
commit | f207eed69e2421695e240aaf47bf881c09cbdd8a (patch) | |
tree | 2b48019c2e9e59515ebf7d7cd665a9821083de9d /libcpp | |
parent | 9a4eb720b343324f7f8fd2dceed5d0347e5a0153 (diff) | |
download | gcc-f207eed69e2421695e240aaf47bf881c09cbdd8a.zip gcc-f207eed69e2421695e240aaf47bf881c09cbdd8a.tar.gz gcc-f207eed69e2421695e240aaf47bf881c09cbdd8a.tar.bz2 |
c++: Macro location fixes [PR 98718]
This fixes some issues with macro maps. We were incorrectly
calculating the number of macro expansions in a location span, and I
had a workaround that partially covered that up. Further, while macro
location spans are monotonic, that is not true of ordinary location
spans. Thus we need to insert an indirection array when binary
searching the latter. (We load ordinary locations before loading
imports, but macro locations afterwards. We make sure an import
location is de-macrofied, if needed.)
PR c++/98718
gcc/cp/
* module.cc (ool): New indirection vector.
(loc_spans::maybe_propagate): Location is not optional.
(loc_spans::open): Likewise. Assert monotonically advancing.
(module_for_ordinary_loc): Use ool indirection vector.
(module_state::write_prepare_maps): Do not count empty macro
expansions. Elide empty spans.
(module_state::write_macro_maps): Skip empty expansions.
(ool_cmp): New qsort comparator.
(module_state::write): Create and destroy ool vector.
(name_pending_imports): Fix dump push/pop.
(preprocess_module): Likewise. Add more dumping.
(preprocessed_module): Likewise.
libcpp/
* include/line-map.h
* line-map.c
gcc/testsuite/
* g++.dg/modules/pr98718_a.C: New.
* g++.dg/modules/pr98718_b.C: New.
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/include/line-map.h | 5 | ||||
-rw-r--r-- | libcpp/line-map.c | 37 |
2 files changed, 24 insertions, 18 deletions
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index d5fc118..40919d0 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1136,8 +1136,9 @@ extern location_t linemap_module_loc extern void linemap_module_reparent (line_maps *, location_t loc, location_t new_parent); -/* Restore the linemap state such that the map at LWM-1 continues. */ -extern void linemap_module_restore +/* Restore the linemap state such that the map at LWM-1 continues. + Return start location of the new map. */ +extern unsigned linemap_module_restore (line_maps *, unsigned lwm); /* Given a logical source location, returns the map which the diff --git a/libcpp/line-map.c b/libcpp/line-map.c index cccacf2..ccabd51 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -621,27 +621,32 @@ linemap_module_reparent (line_maps *set, location_t loc, location_t adoptor) } /* A linemap at LWM-1 was interrupted to insert module locations & imports. - Append a new map, continuing the interrupted one. */ + Append a new map, continuing the interrupted one. Return the start location + of the new map, or 0 if failed (because we ran out of locations. */ -void +unsigned linemap_module_restore (line_maps *set, unsigned lwm) { - if (lwm && lwm != LINEMAPS_USED (set, false)) + linemap_assert (lwm); + + const line_map_ordinary *pre_map + = linemap_check_ordinary (LINEMAPS_MAP_AT (set, false, lwm - 1)); + unsigned src_line = SOURCE_LINE (pre_map, LAST_SOURCE_LINE_LOCATION (pre_map)); + location_t inc_at = pre_map->included_from; + if (const line_map_ordinary *post_map + = (linemap_check_ordinary + (linemap_add (set, LC_RENAME_VERBATIM, + ORDINARY_MAP_IN_SYSTEM_HEADER_P (pre_map), + ORDINARY_MAP_FILE_NAME (pre_map), src_line)))) { - const line_map_ordinary *pre_map - = linemap_check_ordinary (LINEMAPS_MAP_AT (set, false, lwm - 1)); - unsigned src_line = SOURCE_LINE (pre_map, - LAST_SOURCE_LINE_LOCATION (pre_map)); - location_t inc_at = pre_map->included_from; - if (const line_map_ordinary *post_map - = (linemap_check_ordinary - (linemap_add (set, LC_RENAME_VERBATIM, - ORDINARY_MAP_IN_SYSTEM_HEADER_P (pre_map), - ORDINARY_MAP_FILE_NAME (pre_map), src_line)))) - /* linemap_add will think we were included from the same as - the preceeding map. */ - const_cast <line_map_ordinary *> (post_map)->included_from = inc_at; + /* linemap_add will think we were included from the same as the preceeding + map. */ + const_cast <line_map_ordinary *> (post_map)->included_from = inc_at; + + return post_map->start_location; } + + return 0; } /* Returns TRUE if the line table set tracks token locations across |