On 3/13/26 2:38 AM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

OK.

-- >8 --

The testcase crashed because in warn-spec-5_b.C we were writing
diagnostic classifications for pops but not for the things they were
ignoring.  We should have been writing neither, as they all came from an
imported location, but linemap_location_from_module_p was returning
false for locations that originated from macros in a module.

        PR c++/124466

libcpp/ChangeLog:

        * line-map.cc (linemap_location_from_module_p): Resolve loc in
        case it's a macro location.

gcc/testsuite/ChangeLog:

        * g++.dg/modules/warn-spec-5_a.C: New test.
        * g++.dg/modules/warn-spec-5_b.C: New test.
        * g++.dg/modules/warn-spec-5_c.C: New test.

Signed-off-by: Nathaniel Shead <[email protected]>
---
  gcc/testsuite/g++.dg/modules/warn-spec-5_a.C | 12 ++++++++++++
  gcc/testsuite/g++.dg/modules/warn-spec-5_b.C |  8 ++++++++
  gcc/testsuite/g++.dg/modules/warn-spec-5_c.C |  4 ++++
  libcpp/line-map.cc                           |  4 +++-
  4 files changed, 27 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.dg/modules/warn-spec-5_a.C
  create mode 100644 gcc/testsuite/g++.dg/modules/warn-spec-5_b.C
  create mode 100644 gcc/testsuite/g++.dg/modules/warn-spec-5_c.C

diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-5_a.C 
b/gcc/testsuite/g++.dg/modules/warn-spec-5_a.C
new file mode 100644
index 00000000000..aa95b21e1ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/warn-spec-5_a.C
@@ -0,0 +1,12 @@
+// PR c++/124466
+// { dg-additional-options "-fmodules" }
+// { dg-module-cmi A }
+
+export module A;
+
+#define PUSH _Pragma("GCC diagnostic push")
+#define POP _Pragma("GCC diagnostic pop")
+
+PUSH
+#pragma GCC diagnostic ignored "-Wvariadic-macros"
+POP
diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-5_b.C 
b/gcc/testsuite/g++.dg/modules/warn-spec-5_b.C
new file mode 100644
index 00000000000..e5aae843a37
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/warn-spec-5_b.C
@@ -0,0 +1,8 @@
+// PR c++/124466
+// { dg-additional-options "-fmodules -fdump-lang-module" }
+// { dg-module-cmi B }
+
+export module B;
+export import A;
+
+// { dg-final { scan-lang-dump {Diagnostic changes: 0} module } }
diff --git a/gcc/testsuite/g++.dg/modules/warn-spec-5_c.C 
b/gcc/testsuite/g++.dg/modules/warn-spec-5_c.C
new file mode 100644
index 00000000000..e1e943c6832
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/warn-spec-5_c.C
@@ -0,0 +1,4 @@
+// PR c++/124466
+// { dg-additional-options "-fmodules" }
+
+import B;
diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc
index 3dd73a93b98..34f3642258d 100644
--- a/libcpp/line-map.cc
+++ b/libcpp/line-map.cc
@@ -772,7 +772,9 @@ linemap_module_restore (line_maps *set, line_map_uint_t lwm)
  bool
  linemap_location_from_module_p (const line_maps *set, location_t loc)
  {
-  const line_map_ordinary *map = linemap_ordinary_map_lookup (set, loc);
+  const line_map_ordinary *map = nullptr;
+  linemap_resolve_location (set, loc, LRK_SPELLING_LOCATION, &map);
+
    while (map && map->reason != LC_MODULE)
      map = linemap_included_from_linemap (set, map);
    return !!map;

Reply via email to