Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
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.
---
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 45a0309b86e..48ee7d1e790 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 b10442b0960..3b581b3fd36 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))
base-commit: aaa625a51cff750b40bc98f6555adc3f3f5f297b
--
2.51.0