]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: share more trees representing enumerators
authorMarek Polacek <polacek@redhat.com>
Tue, 28 Oct 2025 00:08:00 +0000 (20:08 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 28 Oct 2025 20:28:05 +0000 (16:28 -0400)
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 <jakub@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl.cc

index e2c20a34e6ff4330c97bb561ea0b411b766099b5..751ba40fc7f08329a11436a6208bae9e7838da0e 100644 (file)
@@ -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;