From: Marek Polacek Date: Tue, 28 Oct 2025 00:08:00 +0000 (-0400) Subject: c++: share more trees representing enumerators X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f06ce10a685dc793a8e6dbae00cdef0c3b15cc7;p=thirdparty%2Fgcc.git 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 Reviewed-by: Jason Merrill --- diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e2c20a34e6f..751ba40fc7f 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;