From: Nathan Sidwell <nathan@acm.org>
To: Patrick Palka <ppalka@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: c++: import/export NTTP objects
Date: Thu, 29 Sep 2022 07:43:38 -0400 [thread overview]
Message-ID: <31defc3d-cc4f-f42f-8f7e-a2272998513e@acm.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 320 bytes --]
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.
Patrick, thanks for the testcase, I don't know how to attribute that to
you in the changelog anymore.
nathan
--
Nathan Sidwell
[-- Attachment #2: 0001-c-import-export-NTTP-objects.patch --]
[-- Type: text/x-patch, Size: 4806 bytes --]
From a1f7f9541c2b20eb44750b9c15cd831c62d67f21 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@acm.org>
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 d965017940a..cbf3a77de01 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 00000000000..9bc42bcc05b
--- /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<auto> 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 00000000000..416fd524b2c
--- /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<A{}> 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 00000000000..5c79f5eef68
--- /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<A{}> 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 00000000000..d9515db1140
--- /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<A{}> c0;
+using type = decltype(c0);
+using type = decltype(c1);
+using type = decltype(c2); // bogus error: types of c1 and c2 don't match
--
2.30.2
next reply other threads:[~2022-09-29 11:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 11:43 Nathan Sidwell [this message]
2022-09-29 19:27 ` Patrick Palka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31defc3d-cc4f-f42f-8f7e-a2272998513e@acm.org \
--to=nathan@acm.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=ppalka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).