diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 2518d73c220..db5fa9076c3 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -17194,6 +17194,10 @@ module_state::write_inits (elf_out *to, depset::hash &table, unsigned *crc_ptr) static void post_load_processing () { + /* We mustn't cause a GC, our caller should have arranged for that + not to happen. */ + gcc_checking_assert (function_depth); + if (!post_load_decls) return; @@ -18882,9 +18886,9 @@ lazy_load_pendings (tree decl) pending_table->remove (key); dump.pop (n); - function_depth--; lazy_snum = 0; post_load_processing (); + function_depth--; } timevar_stop (TV_MODULE_IMPORT); diff --git a/gcc/testsuite/g++.dg/modules/pr99423_a.H b/gcc/testsuite/g++.dg/modules/pr99423_a.H new file mode 100644 index 00000000000..db3406c6dd3 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99423_a.H @@ -0,0 +1,13 @@ +// PR 99423 ICE seeing GC freed entities +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } +template +struct pair +{ + pair() { } +}; + +inline pair blob () +{ + return {}; +} diff --git a/gcc/testsuite/g++.dg/modules/pr99423_b.H b/gcc/testsuite/g++.dg/modules/pr99423_b.H new file mode 100644 index 00000000000..c02ab29a3ee --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr99423_b.H @@ -0,0 +1,6 @@ +// { dg-additional-options {-fmodule-header --param ggc-min-expand=0 --param ggc-min-heapsize=0} } +// { dg-module-cmi {} } + +import "pr99423_a.H"; + +pair boom();