]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Support re-streaming TU_LOCAL_ENTITYs [PR120412]
authorNathaniel Shead <nathanieloshead@gmail.com>
Sat, 24 May 2025 00:56:22 +0000 (10:56 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Thu, 24 Jul 2025 00:56:06 +0000 (10:56 +1000)
When emitting a primary module interface, we must re-stream any TU-local
entities that we saw in a partition.  This patch adds the missing
members from core_vals.

As a drive-by fix, in some cases we might have a typedef referring to a
TU-local entity; we need to handle that case as well.

PR c++/120412

gcc/cp/ChangeLog:

* module.cc (trees_out::core_vals): Write TU_LOCAL_ENTITY bits.
(trees_in::core_vals): Read it.
(trees_in::tree_node): Handle TU_LOCAL_ENTITY typedefs.

gcc/testsuite/ChangeLog:

* g++.dg/modules/internal-14_a.C: New test.
* g++.dg/modules/internal-14_b.C: New test.
* g++.dg/modules/internal-14_c.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit be81c5c01c243013c4bac0718e63e0fdc132d384)

gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/internal-14_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/internal-14_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/internal-14_c.C [new file with mode: 0644]

index e66f725c20d33c3d7b577482d151ef424f517ace..46d3a3fc14e4449f5b7edbc896cc9be0dae307b2 100644 (file)
@@ -6784,6 +6784,13 @@ trees_out::core_vals (tree t)
       if (streaming_p ())
        WU (((lang_tree_node *)t)->trait_expression.kind);
       break;
+
+    case TU_LOCAL_ENTITY:
+      WT (((lang_tree_node *)t)->tu_local_entity.name);
+      if (state)
+       state->write_location
+         (*this, ((lang_tree_node *)t)->tu_local_entity.loc);
+      break;
     }
 
   if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
@@ -7327,6 +7334,11 @@ trees_in::core_vals (tree t)
       RT (((lang_tree_node *)t)->trait_expression.type2);
       RUC (cp_trait_kind, ((lang_tree_node *)t)->trait_expression.kind);
       break;
+
+    case TU_LOCAL_ENTITY:
+      RT (((lang_tree_node *)t)->tu_local_entity.name);
+      ((lang_tree_node *)t)->tu_local_entity.loc
+       = state->read_location (*this);
     }
 
   if (CODE_CONTAINS_STRUCT (code, TS_TYPED))
@@ -10135,7 +10147,8 @@ trees_in::tree_node (bool is_use)
            && dump ("Read %stypedef %C:%N",
                     DECL_IMPLICIT_TYPEDEF_P (res) ? "implicit " : "",
                     TREE_CODE (res), res);
-         res = TREE_TYPE (res);
+         if (TREE_CODE (res) != TU_LOCAL_ENTITY)
+           res = TREE_TYPE (res);
        }
       break;
 
diff --git a/gcc/testsuite/g++.dg/modules/internal-14_a.C b/gcc/testsuite/g++.dg/modules/internal-14_a.C
new file mode 100644 (file)
index 0000000..07eb965
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/120412
+// { dg-additional-options "-fmodules -std=c++20 -Wtemplate-names-tu-local" }
+// { dg-module-cmi m:part }
+
+export module m:part;
+
+export template <typename F>
+auto fun1(F) {
+  return true;
+}
+
+using Dodgy = decltype([]{});
+
+export template <typename T>
+auto fun2(T&&) {  // { dg-warning "TU-local" }
+  return fun1(Dodgy{});
+}
diff --git a/gcc/testsuite/g++.dg/modules/internal-14_b.C b/gcc/testsuite/g++.dg/modules/internal-14_b.C
new file mode 100644 (file)
index 0000000..ad3b09d
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/120412
+// { dg-additional-options "-fmodules -std=c++20 -Wtemplate-names-tu-local" }
+// { dg-module-cmi m }
+
+export module m;
+export import :part;
diff --git a/gcc/testsuite/g++.dg/modules/internal-14_c.C b/gcc/testsuite/g++.dg/modules/internal-14_c.C
new file mode 100644 (file)
index 0000000..4f8e785
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/120412
+// { dg-additional-options "-fmodules -std=c++20" }
+
+import m;
+
+int main() {
+  // { dg-error "instantiation exposes TU-local entity '(fun1|Dodgy)'" "" { target *-*-* } 0 }
+  fun2(123);  // { dg-message "required from here" }
+}