https://gcc.gnu.org/g:c38bf35f0c7fa1dadaae4c2811b24aa4cd764cab

commit r16-5305-gc38bf35f0c7fa1dadaae4c2811b24aa4cd764cab
Author: Jason Merrill <[email protected]>
Date:   Sat Nov 15 23:13:37 2025 +0530

    c++/modules: explicit inst of constructor
    
    The extern template __shared_ptr<filesystem::_Dir> in bits/fs_dir.h was
    leading to an ICE in import_export_decl in 29_atomics/atomic_ref/address.cc
    because we had the nonsensical combination of DECL_REALLY_EXTERN and
    !DECL_INTERFACE_KNOWN.  This turned out to be because mark_decl_instantiated
    was exiting early if TREE_ASM_WRITTEN since way back in the pre-cgraph days,
    and expand_or_defer_fn_1 sets TREE_ASM_WRITTEN on maybe-in-charge ctors.
    The mark_decl_instantiated code is long-obsolete, so let's just remove it.
    
    gcc/cp/ChangeLog:
    
            * module.cc (trees_out::write_function_def): Check flag consistency.
            * pt.cc (mark_decl_instantiated): Ignore TREE_ASM_WRITTEN.

Diff:
---
 gcc/cp/module.cc | 7 +++++++
 gcc/cp/pt.cc     | 5 -----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 45a0309b86e6..48ee7d1e7904 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -12914,6 +12914,13 @@ trees_out::write_function_def (tree decl)
                    && (get_importer_interface (decl)
                        != importer_interface::external));
 
+      /* Make sure DECL_REALLY_EXTERN and DECL_INTERFACE_KNOWN are consistent
+        on non-templates or we'll crash later in import_export_decl.  */
+      gcc_checking_assert (flags || DECL_INTERFACE_KNOWN (decl)
+                          || (DECL_LANG_SPECIFIC (decl)
+                              && DECL_TEMPLATE_INFO (decl)
+                              && uses_template_parms (DECL_TI_ARGS (decl))));
+
       if (f)
        {
          flags |= 2;
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index b10442b09609..3b581b3fd369 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -26379,11 +26379,6 @@ mark_decl_instantiated (tree result, int extern_p)
 {
   SET_DECL_EXPLICIT_INSTANTIATION (result);
 
-  /* If this entity has already been written out, it's too late to
-     make any modifications.  */
-  if (TREE_ASM_WRITTEN (result))
-    return;
-
   /* consteval functions are never emitted.  */
   if (TREE_CODE (result) == FUNCTION_DECL
       && DECL_IMMEDIATE_FUNCTION_P (result))

Reply via email to