]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Remember that header units have CMIs
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 23 May 2024 12:56:52 +0000 (22:56 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 24 May 2024 14:10:41 +0000 (00:10 +1000)
This appears to be an oversight in the definition of module_has_cmi_p.
This change will allow us to use the function directly in more places
that need to additional work only if generating a module CMI in the
future, allowing us to do additional work only when we know we need it.

gcc/cp/ChangeLog:

* cp-tree.h (module_has_cmi_p): Also include header units.
(module_maybe_has_cmi_p): Update comment.
* module.cc (set_defining_module): Only need to track
declarations for later exporting if the module may have a CMI.
(set_defining_module_for_partial_spec): Likewise.
* name-lookup.cc (pushdecl): Likewise.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/cp-tree.h
gcc/cp/module.cc
gcc/cp/name-lookup.cc

index 7ae5b876735ce133628fa1b2a08a8c11e89bbb8a..655850a9ab610677a34b3dbbc9a54c6a118e632e 100644 (file)
@@ -7381,7 +7381,7 @@ inline bool module_interface_p ()
 inline bool module_partition_p ()
 { return module_kind & MK_PARTITION; }
 inline bool module_has_cmi_p ()
-{ return module_kind & (MK_INTERFACE | MK_PARTITION); }
+{ return module_kind & (MK_INTERFACE | MK_PARTITION | MK_HEADER); }
 
 inline bool module_purview_p ()
 { return module_kind & MK_PURVIEW; }
@@ -7393,9 +7393,8 @@ inline bool named_module_purview_p ()
 inline bool named_module_attach_p ()
 { return named_module_p () && module_attach_p (); }
 
-/* We don't know if this TU will have a CMI while parsing the GMF,
-   so tentatively assume that it might, for the purpose of determining
-   whether no-linkage decls could be used by an importer.  */
+/* Like module_has_cmi_p, but tentatively assumes that this TU may have a
+   CMI if we haven't seen the module-declaration yet.  */
 inline bool module_maybe_has_cmi_p ()
 { return module_has_cmi_p () || (named_module_p () && !module_purview_p ()); }
 
index 3ca963cb3e964db2adb33950c26329f79792a844..6cd7d9e0b931123068489085c6e8fd373dc5d979 100644 (file)
@@ -19221,7 +19221,7 @@ set_defining_module (tree decl)
   gcc_checking_assert (!DECL_LANG_SPECIFIC (decl)
                       || !DECL_MODULE_IMPORT_P (decl));
 
-  if (module_p ())
+  if (module_maybe_has_cmi_p ())
     {
       /* We need to track all declarations within a module, not just those
         in the module purview, because we don't necessarily know yet if
@@ -19261,7 +19261,7 @@ set_defining_module (tree decl)
 void
 set_defining_module_for_partial_spec (tree decl)
 {
-  if (module_p ()
+  if (module_maybe_has_cmi_p ()
       && DECL_IMPLICIT_TYPEDEF_P (decl)
       && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl)))
     vec_safe_push (partial_specializations, decl);
index 78f08acffaa07d366740351d75c6ef478ed7584b..f1f8c19feb1cf35328d5bbee86748e1d840a060b 100644 (file)
@@ -4103,7 +4103,7 @@ pushdecl (tree decl, bool hiding)
 
          if (level->kind == sk_namespace
              && TREE_PUBLIC (level->this_entity)
-             && module_p ())
+             && module_maybe_has_cmi_p ())
            maybe_record_mergeable_decl (slot, name, decl);
        }
     }