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

--- Comment #11 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>:

https://gcc.gnu.org/g:716af95fd454871473c4b118b8412b6a68459b75

commit r14-9948-716af95fd454871473c4b118b8412b6a68459b75
Author: Patrick Palka <ppa...@redhat.com>

    c++/modules: local type merging [PR99426]

    One known missing piece in the modules implementation is merging of a
    streamed-in local type (class or enum) with the corresponding in-TU
    version of the local type.  This missing piece turns out to cause a
    hard-to-reduce use-after-free GC issue due to the entity_ary not being
    marked as a GC root (deliberately), and manifests as a serialization
    error on stream-in as in PR99426 (see comment #6 for a reduction).  It's
    also reproducible on trunk when running the xtreme-header tests without
    -fno-module-lazy.

    This patch implements this missing piece, making us merge such local
    types according to their position within the containing function's
    definition, analogous to how we merge FIELD_DECLs of a class according
    to their index in the TYPE_FIELDS list.

            PR c++/99426

    gcc/cp/ChangeLog:

            * module.cc (merge_kind::MK_local_type): New enumerator.
            (merge_kind_name): Update.
            (trees_out::chained_decls): Move BLOCK-specific handling
            of DECL_LOCAL_DECL_P decls to ...
            (trees_out::core_vals) <case BLOCK>: ... here.  Stream
            BLOCK_VARS manually.
            (trees_in::core_vals) <case BLOCK>: Stream BLOCK_VARS
            manually.  Handle deduplicated local types..
            (trees_out::key_local_type): Define.
            (trees_in::key_local_type): Define.
            (trees_out::get_merge_kind) <case FUNCTION_DECL>: Return
            MK_local_type for a local type.
            (trees_out::key_mergeable) <case FUNCTION_DECL>: Use
            key_local_type.
            (trees_in::key_mergeable) <case FUNCTION_DECL>: Likewise.
            (trees_in::is_matching_decl): Be flexible with type mismatches
            for local entities.
            (trees_in::register_duplicate): Also register the
            DECL_TEMPLATE_RESULT of a TEMPLATE_DECL as a duplicate.
            (depset_cmp): Return 0 for equal IDENTIFIER_HASH_VALUEs.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/merge-17.h: New test.
            * g++.dg/modules/merge-17_a.H: New test.
            * g++.dg/modules/merge-17_b.C: New test.
            * g++.dg/modules/xtreme-header-7_a.H: New test.
            * g++.dg/modules/xtreme-header-7_b.C: New test.

    Reviewed-by: Jason Merrill <ja...@redhat.com>

Reply via email to