https://gcc.gnu.org/g:4f06ce10a685dc793a8e6dbae00cdef0c3b15cc7
commit r16-4698-g4f06ce10a685dc793a8e6dbae00cdef0c3b15cc7 Author: Marek Polacek <[email protected]> Date: Mon Oct 27 20:08:00 2025 -0400 c++: share more trees representing enumerators This came up in Reflection where an assert fails because we have two different trees for same enumerators. The reason is that in finish_enum_value_list we copy_node when converting the enumerators. It should be more efficient to share trees for identical enumerators. This fix was proposed by Jakub. gcc/cp/ChangeLog: * decl.cc (finish_enum_value_list): Use fold_convert instead of copy_node. Co-authored-by: Jakub Jelinek <[email protected]> Reviewed-by: Jason Merrill <[email protected]> Diff: --- gcc/cp/decl.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e2c20a34e6ff..751ba40fc7f0 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -18958,13 +18958,9 @@ finish_enum_value_list (tree enumtype) value = perform_implicit_conversion (underlying_type, DECL_INITIAL (decl), tf_warning_or_error); - /* Do not clobber shared ints. */ - if (value != error_mark_node) - { - value = copy_node (value); + /* Do not clobber shared ints. But do share identical enumerators. */ + value = fold_convert (enumtype, value); - TREE_TYPE (value) = enumtype; - } DECL_INITIAL (decl) = value; if (export_p) DECL_MODULE_EXPORT_P (decl) = true;
