https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114630
--- Comment #16 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Jason Merrill <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:b360d4aafc1356386313c7392f7444b3fc356681 commit r15-7906-gb360d4aafc1356386313c7392f7444b3fc356681 Author: Jason Merrill <ja...@redhat.com> Date: Thu Mar 6 12:39:36 2025 -0500 c++/modules: purview of explicit instantiations [PR114630] When calling instantiate_pending_templates at end of parsing, any new functions that are instantiated from this point have their module purview set based on the current value of module_kind. This is unideal, however, as the modules code will then treat these instantiations as reachable and cause large swathes of the GMF to be emitted into the module CMI, despite no code in the actual module purview referencing it. This patch fixes this by setting DECL_MODULE_PURVIEW_P as appropriate when we see an explicit instantiation, and adjusting module_kind accordingly during deferred instantiation, meaning that GMF entities won't be counted as reachable unless referenced by an actually reachable entity. Note that purviewness and attachment etc. is generally only determined by the base template: this is purely for determining whether an explicit instantiation is in the module purview and hence whether it should be streamed out. See the comment on 'set_instantiating_module'. Incidentally, since the "xtreme" testcases are deliberately large (and this commit adds another one), let's make sure we only run them once. PR c++/114630 PR c++/114795 gcc/cp/ChangeLog: * pt.cc (reopen_tinst_level): Set or clear MK_PURVIEW. (mark_decl_instantiated): Call set_instantiating_module. (instantiate_pending_templates): Save and restore module_kind so it isn't affected by reopen_tinst_level. gcc/testsuite/ChangeLog: * g++.dg/modules/modules.exp: Run xtreme tests once. * g++.dg/modules/gmf-3.C: New test. * g++.dg/modules/gmf-4.C: New test. * g++.dg/modules/gmf-xtreme.C: New test. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> Co-authored-by: Nathaniel Shead <nathanielosh...@gmail.com>