On Mon, Oct 27, 2025 at 08:36:51PM -0400, Marek Polacek wrote:
> 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.
I wonder if this wouldn't be better
value = fold_convert (enumtype, value);
so that under the hood it does fold_convert_const_int_from_int aka
tree arg1_type = TREE_TYPE (arg1);
unsigned prec = MAX (TYPE_PRECISION (arg1_type), TYPE_PRECISION (type));
return force_fit_type (type, wide_int::from (wi::to_wide (arg1), prec,
TYPE_SIGN (arg1_type)),
!POINTER_TYPE_P (TREE_TYPE (arg1)),
TREE_OVERFLOW (arg1));
and thus preserves TREE_OVERFLOW. fold_convert even will handle
error_mark_node right.
The important part is that if there wasn't an overflow, it will do
wide_int_to_tree and thus share the INTEGER_CST value rather than
making a copy.
Jakub