-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Patrick Palka
committed
Apr 12, 2024
1 parent
df7bfdb
commit 716af95
Showing
6 changed files
with
222 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// PR c++/99426 | ||
|
||
inline auto f() { | ||
struct A { int m = 42; }; | ||
return A{}; | ||
} | ||
|
||
template<class T> | ||
auto ft() { | ||
decltype(+T()) x; | ||
return [&x] { }; | ||
} | ||
|
||
inline auto g() { | ||
enum E { e }; | ||
return e; | ||
} | ||
|
||
template<class T> | ||
auto gt() { | ||
enum E : T { e }; | ||
return e; | ||
} | ||
|
||
inline auto h0() { | ||
struct { int m; } a0; | ||
struct { char n; } a1; | ||
return a0; | ||
} | ||
|
||
inline auto h1() { | ||
struct { int m; } a0; | ||
struct { char n; } a1; | ||
return a1; | ||
} | ||
|
||
template<class T> | ||
inline auto h0t() { | ||
struct { int m; } a0; | ||
struct { char n; } a1; | ||
return a0; | ||
} | ||
|
||
template<class T> | ||
inline auto h1t() { | ||
struct { int m; } a0; | ||
struct { char n; } a1; | ||
return a1; | ||
} | ||
|
||
using ty1 = decltype(f()); | ||
using ty2 = decltype(ft<int>()); | ||
using ty3 = decltype(g()); | ||
using ty4 = decltype(gt<int>()); | ||
using ty5 = decltype(h0()); | ||
using ty6 = decltype(h0t<int>()); | ||
using ty7 = decltype(h1()); | ||
using ty8 = decltype(h1t<int>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// { dg-additional-options "-fmodule-header" } | ||
// { dg-module-cmi {} } | ||
#include "merge-17.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// { dg-additional-options "-fmodules-ts -fno-module-lazy" } | ||
#include "merge-17.h" | ||
import "merge-17_a.H"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// { dg-additional-options -fmodule-header } | ||
|
||
// { dg-module-cmi {} } | ||
#include "xtreme-header.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// A version of xtreme-header_b.C that doesn't use -fno-module-lazy. | ||
// { dg-additional-options -fmodules-ts } | ||
|
||
#include "xtreme-header.h" | ||
import "xtreme-header-7_a.H"; |