]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: losslessly encode TYPENAME_TYPE tag
authorPatrick Palka <ppalka@redhat.com>
Mon, 15 Dec 2025 20:03:39 +0000 (15:03 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 15 Dec 2025 20:03:39 +0000 (15:03 -0500)
commita7a3d1d64d3b275d03382b84f04a2bbda45c0b7d
tree90cfba85acf0ad3229b4d8021de20af5a780d662
parent09a9ae0dcb34ef7c57ef997f017eb5a2ddb926d4
c++: losslessly encode TYPENAME_TYPE tag

We currently have 7 distinct tag_types, but our TYPENAME_TYPE
representation effectively only differentiates between 4 of them at the
expense of struct_type (which gets conflated with class_type),
none_type and scope_type (which get conflated with typename_type).

struct_type / class_type conflation is mostly harmless, but it
probably affects -Wmismatched-tags.  none_type / typename_type too
should be harmless.  But scope_type / typename_type conflation is
problematic because scope_type indicates a type-only lookup unlike
typename_type.

This patch makes our representation of TYPENAME_TYPE encode the numeric
tag type value losslessly using the first three adjacent tree flag bits.
We already use three flag bits for the tag encoding (but inefficiently)
so no additional space is needed.

gcc/cp/ChangeLog:

* cp-tree.h (TYPENAME_TYPE_TAG_BIT_0): New.
(TYPENAME_TYPE_TAG_BIT_1): New.
(TYPENAME_TYPE_TAG_BIT_2): New.
(TYPENAME_IS_ENUM_P): Use get_typename_tag.
(TYPENAME_IS_CLASS_P): Rename to ...
(TYPENAME_IS_CLASS_OR_STRUCT_P): ... this, and use
get_typename_tag.
(TYPENAME_IS_UNION_P): Use get_typename_tag.
(TYPENAME_IS_RESOLVING_P): Use TREE_LANG_FLAG_3
instead of _2.
(get_typename_tag): New.
(set_typename_tag): New.
(tag_name): Declare.
* decl.cc (typename_info): Replace bool fields with a single
tag_types field.
(typename_hasher::equal): Adjust.
(build_typename_type): Adjust.
(tag_name): Handle none_type and scope_type.
* error.cc (dump_type) <case TYPENAME_TYPE>: Use tag_name.
* module.cc (trees_out::type_node) <case TYPENAME_TYPE>: Use
get_typename_tag.
* pt.cc (tsubst) <case TYPENAME_TYPE>: Likewise.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/error.cc
gcc/cp/module.cc
gcc/cp/pt.cc