https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118961

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nsh...@gcc.gnu.org>:

https://gcc.gnu.org/g:3258c89fbb092412a69b689425e77972e7a1c567

commit r15-9024-g3258c89fbb092412a69b689425e77972e7a1c567
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Fri Mar 28 23:38:26 2025 +1100

    c++/modules: Fix modules and LTO with header units [PR118961]

    This patch makes some adjustments required to get a simple modules
    testcase working with LTO.  There are two main issues fixed.

    Firstly, modules only streams the maybe-in-charge constructor, and any
    clones are recreated on stream-in.  These clones are copied from the
    existing function decl and then adjusted.  This caused issues because
    the clones were getting incorrectly marked as abstract, since after
    clones have been created (in the imported file) the maybe-in-charge decl
    gets marked as abstract.  So this patch just ensures that clones are
    always created as non-abstract.

    The second issue is that we need to explicitly tell cgraph that explicit
    instantiations need to be emitted, otherwise LTO will elide them (as
    they don't necessarily appear to be used directly) and cause link
    errors.  Additionally, expand_or_defer_fn doesn't setup comdat groups
    for explicit instantiations, so we need to do that here as well.
    Currently this is all handled in 'mark_decl_instantiated'; this patch
    splits out the linkage handling into a separate function that we can
    call from modules code, maybe in GCC16 we could move this somewhere more
    central.

            PR c++/118961

    gcc/cp/ChangeLog:

            * class.cc (copy_fndecl_with_name): Mark clones as non-abstract.
            * cp-tree.h (setup_explicit_instantiation_definition_linkage):
            Declare new function.
            * module.cc (trees_in::read_var_def): Use it.
            (module_state::read_cluster): Likewise.
            * pt.cc (setup_explicit_instantiation_definition_linkage): New
            function.
            (mark_decl_instantiated): Use it.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/lto-1.h: New test.
            * g++.dg/modules/lto-1_a.H: New test.
            * g++.dg/modules/lto-1_b.C: New test.
            * g++.dg/modules/lto-1_c.C: New test.
            * g++.dg/modules/lto-2_a.H: New test.
            * g++.dg/modules/lto-2_b.C: New test.
            * g++.dg/modules/lto-3_a.H: New test.
            * g++.dg/modules/lto-3_b.C: New test.

    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
    Reviewed-by: Jason Merrill <ja...@redhat.com>

Reply via email to