From a1f7f9541c2b20eb44750b9c15cd831c62d67f21 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 28 Sep 2022 09:21:14 -0700 Subject: [PATCH] c++: import/export NTTP objects This adds smarts to the module machinery to handle NTTP object VAR_DECLs. Like typeinfo objects, these must be ignored in the symbol table, streamed specially and recreated on stream in. gcc/cp/ PR c++/100616 * module.cc (enum tree_tag): Add tt_nttp_var. (trees_out::decl_node): Handle NTTP objects. (trees_in::tree_node): Handle tt_nttp_var. (depset::hash::add_binding_entry): Skip NTTP objects. gcc/testsuite/ PR c++/100616 * g++.dg/modules/100616_a.H: New. * g++.dg/modules/100616_b.C: New. * g++.dg/modules/100616_c.C: New. * g++.dg/modules/100616_d.C: New. --- gcc/cp/module.cc | 35 +++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/modules/100616_a.H | 5 +++++ gcc/testsuite/g++.dg/modules/100616_b.C | 7 +++++++ gcc/testsuite/g++.dg/modules/100616_c.C | 7 +++++++ gcc/testsuite/g++.dg/modules/100616_d.C | 10 ++++++++++ 5 files changed, 64 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/100616_a.H create mode 100644 gcc/testsuite/g++.dg/modules/100616_b.C create mode 100644 gcc/testsuite/g++.dg/modules/100616_c.C create mode 100644 gcc/testsuite/g++.dg/modules/100616_d.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index d965017..cbf3a77 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -2737,6 +2737,7 @@ enum tree_tag { tt_tinfo_var, /* Typeinfo object. */ tt_tinfo_typedef, /* Typeinfo typedef. */ tt_ptrmem_type, /* Pointer to member type. */ + tt_nttp_var, /* NTTP_OBJECT VAR_DECL. */ tt_parm, /* Function parameter or result. */ tt_enum_value, /* An enum value. */ @@ -8548,6 +8549,21 @@ trees_out::decl_node (tree decl, walk_kind ref) } return false; } + + if (DECL_NTTP_OBJECT_P (decl)) + { + /* A NTTP parm object. */ + if (streaming_p ()) + i (tt_nttp_var); + tree_node (tparm_object_argument (decl)); + tree_node (DECL_NAME (decl)); + int tag = insert (decl); + if (streaming_p ()) + dump (dumper::TREE) + && dump ("Wrote nttp object:%d %N", tag, DECL_NAME (decl)); + return false; + } + break; case TYPE_DECL: @@ -9627,6 +9643,21 @@ trees_in::tree_node (bool is_use) } break; + case tt_nttp_var: + /* An NTTP object. */ + { + tree init = tree_node (); + tree name = tree_node (); + if (!get_overrun ()) + { + res = get_template_parm_object (init, name); + int tag = insert (res); + dump (dumper::TREE) + && dump ("Created nttp object:%d %N", tag, name); + } + } + break; + case tt_enum_value: /* An enum const value. */ { @@ -12760,6 +12791,10 @@ depset::hash::add_binding_entity (tree decl, WMB_Flags flags, void *data_) /* Ignore TINFO things. */ return false; + if (TREE_CODE (decl) == VAR_DECL && DECL_NTTP_OBJECT_P (decl)) + /* Ignore NTTP objects. */ + return false; + if (!(flags & WMB_Using) && CP_DECL_CONTEXT (decl) != data->ns) { /* A using that lost its wrapper or an unscoped enum diff --git a/gcc/testsuite/g++.dg/modules/100616_a.H b/gcc/testsuite/g++.dg/modules/100616_a.H new file mode 100644 index 0000000..9bc42bc --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/100616_a.H @@ -0,0 +1,5 @@ +// { dg-additional-options {-std=c++20 -fmodule-header} } +// { dg-module-cmi {} } + +template struct C { }; +struct A { }; diff --git a/gcc/testsuite/g++.dg/modules/100616_b.C b/gcc/testsuite/g++.dg/modules/100616_b.C new file mode 100644 index 0000000..416fd52 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/100616_b.C @@ -0,0 +1,7 @@ +// { dg-additional-options {-std=c++20 -fmodules-ts} } + +export module pr100616_b; +// { dg-module-cmi pr100616_b } + +import "100616_a.H"; +export C c1; diff --git a/gcc/testsuite/g++.dg/modules/100616_c.C b/gcc/testsuite/g++.dg/modules/100616_c.C new file mode 100644 index 0000000..5c79f5e --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/100616_c.C @@ -0,0 +1,7 @@ +// { dg-additional-options {-std=c++20 -fmodules-ts} } + +export module pr100616_c; +// { dg-module-cmi pr100616_c } + +import "100616_a.H"; +export C c2; diff --git a/gcc/testsuite/g++.dg/modules/100616_d.C b/gcc/testsuite/g++.dg/modules/100616_d.C new file mode 100644 index 0000000..d9515db --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/100616_d.C @@ -0,0 +1,10 @@ +// { dg-additional-options {-std=c++20 -fmodules-ts} } + +import "100616_a.H"; +import pr100616_b; +import pr100616_c; + +C c0; +using type = decltype(c0); +using type = decltype(c1); +using type = decltype(c2); // bogus error: types of c1 and c2 don't match -- 2.7.4