From a5933118f34a97463ffa765744eedf27b9c2c68f Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 20 Nov 2024 16:20:52 +0100 Subject: c++: modules and #pragma diagnostic To respect the #pragma diagnostic lines in libstdc++ headers when compiling with module std, we need to represent them in the module. I think it's reasonable to give serializers direct access to the underlying data, as here with get_classification_history. This is a different approach from how Jakub made PCH streaming members of diagnostic_option_classifier, but it seems to me that modules handling belongs in module.cc. libcpp/ChangeLog: * line-map.cc (linemap_location_from_module_p): Add. * include/line-map.h: Declare it. gcc/ChangeLog: * diagnostic.h (diagnostic_option_classifier): Friend diagnostic_context. (diagnostic_context::get_classification_history): New. gcc/cp/ChangeLog: * module.cc (module_state::write_diagnostic_classification): New. (module_state::write_begin): Call it. (module_state::read_diagnostic_classification): New. (module_state::read_initial): Call it. (dk_string, dump_dc_change): New. gcc/testsuite/ChangeLog: * g++.dg/modules/warn-spec-3_a.C: New test. * g++.dg/modules/warn-spec-3_b.C: New test. * g++.dg/modules/warn-spec-3_c.C: New test. --- libcpp/include/line-map.h | 4 ++++ libcpp/line-map.cc | 11 +++++++++++ 2 files changed, 15 insertions(+) (limited to 'libcpp') diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 83ebbde474d..21a59af2236 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1111,6 +1111,10 @@ extern location_t linemap_module_loc extern void linemap_module_reparent (line_maps *, location_t loc, location_t new_parent); +/* TRUE iff the location comes from a module import. */ +extern bool linemap_location_from_module_p + (const line_maps *, location_t); + /* Restore the linemap state such that the map at LWM-1 continues. Return start location of the new map. */ extern location_t linemap_module_restore diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc index 284af5781dc..33701b519e1 100644 --- a/libcpp/line-map.cc +++ b/libcpp/line-map.cc @@ -767,6 +767,17 @@ linemap_module_restore (line_maps *set, line_map_uint_t lwm) return 0; } +/* TRUE iff the location comes from a module import. */ + +bool +linemap_location_from_module_p (const line_maps *set, location_t loc) +{ + const line_map_ordinary *map = linemap_ordinary_map_lookup (set, loc); + while (map && map->reason != LC_MODULE) + map = linemap_included_from_linemap (set, map); + return !!map; +} + /* Returns TRUE if the line table set tracks token locations across macro expansion, FALSE otherwise. */ -- cgit v1.2.3