Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15? -- >8 --
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 <nathanielosh...@gmail.com> --- gcc/cp/module.cc | 15 ++++++++++++++- gcc/testsuite/g++.dg/modules/internal-14_a.C | 17 +++++++++++++++++ gcc/testsuite/g++.dg/modules/internal-14_b.C | 6 ++++++ gcc/testsuite/g++.dg/modules/internal-14_c.C | 9 +++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/internal-14_a.C create mode 100644 gcc/testsuite/g++.dg/modules/internal-14_b.C create mode 100644 gcc/testsuite/g++.dg/modules/internal-14_c.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 17c040d26b0..16322fddde7 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -6774,6 +6774,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)) @@ -7317,6 +7324,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)) @@ -10125,7 +10137,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 index 00000000000..07eb9658951 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/internal-14_a.C @@ -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 index 00000000000..ad3b09d0722 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/internal-14_b.C @@ -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 index 00000000000..4f8e785ce87 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/internal-14_c.C @@ -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" } +} -- 2.47.0