]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: local type merging [PR99426]
authorPatrick Palka <ppalka@redhat.com>
Fri, 12 Apr 2024 19:50:04 +0000 (15:50 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 12 Apr 2024 19:50:04 +0000 (15:50 -0400)
commit716af95fd454871473c4b118b8412b6a68459b75
treeba3d0c85b287170d2bcdb40029d76742207dcbec
parentdf7bfdb7dbf2d46aa5768a0280d4dcfcc868b7f9
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 <jason@redhat.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/merge-17.h [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/merge-17_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/merge-17_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/xtreme-header-7_a.H [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/xtreme-header-7_b.C [new file with mode: 0644]