]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: purview of explicit instantiations [PR114630]
authorJason Merrill <jason@redhat.com>
Thu, 6 Mar 2025 17:39:36 +0000 (12:39 -0500)
committerJason Merrill <jason@redhat.com>
Sat, 8 Mar 2025 14:54:41 +0000 (09:54 -0500)
commitb360d4aafc1356386313c7392f7444b3fc356681
treec1e359f3e010529c14f3325059ea0ac3077a07b5
parentd456728667ddace4cf34ac7a5e63cb67de4c6257
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 <nathanieloshead@gmail.com>
Co-authored-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/modules/gmf-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/gmf-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/gmf-xtreme.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/modules.exp