https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120040
--- Comment #2 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:e3db74150f5eee104b996cc6f69d3e721b8832b9 commit r16-1736-ge3db74150f5eee104b996cc6f69d3e721b8832b9 Author: Nathaniel Shead <nathanielosh...@gmail.com> Date: Tue May 20 23:07:20 2025 +1000 c++/modules: Implement streaming of uncontexted TYPE_DECLs [PR98735] Currently, most declarations must have a DECL_CONTEXT for modules streaming to behave correctly, so that they can have an appropriate merge key generated and be correctly deduplicated on import. There are a few exceptions, however, for internally generated declarations that will never be merged and don't necessarily have an appropriate parent to key off for the context. One case that's come up a few times is TYPE_DECLs, especially temporary RECORD_TYPEs used as intermediaries within expressions. Previously I've tried to give all such types a DECL_CONTEXT, but in some cases that has ended up being infeasible, such as with the types generated by UBSan (which are shared with the C frontend and don't know their context, especially when created at global scope). Additionally, these types often don't have many of the parts that a normal struct declaration created via parsing user code would have, which confuses module streaming. Given that these types are typically intended to be one-off and unique anyway, this patch instead adds support for by-value streaming of uncontexted TYPE_DECLs. The patch only support streaming the bare minimum amount of fields needed for the cases I've come across so far; in general the preference should still be to ensure that DECL_CONTEXT is set where possible. PR c++/98735 PR c++/120040 gcc/cp/ChangeLog: * module.cc (trees_out::tree_value): Write TYPE_DECLs. (trees_in::tree_value): Read TYPE_DECLs. (trees_out::tree_node): Support uncontexted TYPE_DECLs, and ensure that all parts of a by-value decl are marked for streaming. (trees_out::get_merge_kind): Treat members of uncontexted types as always unique. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> Reviewed-by: Jason Merrill <ja...@redhat.com>