]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: import/export NTTP objects
authorNathan Sidwell <nathan@acm.org>
Wed, 28 Sep 2022 16:21:14 +0000 (09:21 -0700)
committerNathan Sidwell <nathan@acm.org>
Thu, 29 Sep 2022 11:41:59 +0000 (04:41 -0700)
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
gcc/testsuite/g++.dg/modules/100616_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/100616_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/100616_c.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/100616_d.C [new file with mode: 0644]

index d965017940a010f2cbd0bd874702fb814887b6f9..cbf3a77de01afdef4cad9666ba0727f28782129e 100644 (file)
@@ -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 (file)
index 0000000..9bc42bc
--- /dev/null
@@ -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 (file)
index 0000000..416fd52
--- /dev/null
@@ -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 (file)
index 0000000..5c79f5e
--- /dev/null
@@ -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 (file)
index 0000000..d9515db
--- /dev/null
@@ -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