Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
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 wide_int_to_tree instead of
        copy_node.

Co-authored-by: Jakub Jelinek <[email protected]>
---
 gcc/cp/decl.cc | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index e2c20a34e6f..feddfb5eb99 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -18958,13 +18958,10 @@ 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.  */
+      if (TREE_CODE (value) == INTEGER_CST)
+       value = wide_int_to_tree (enumtype, wi::to_wide (value));
 
-         TREE_TYPE (value) = enumtype;
-       }
       DECL_INITIAL (decl) = value;
       if (export_p)
        DECL_MODULE_EXPORT_P (decl) = true;

base-commit: 3d09cd9311d8a08b1b5046ea0a3c7f30ec50ca0d
-- 
2.51.0

Reply via email to