https://gcc.gnu.org/g:451be569e4fdc18e6155a54f53a16f7b3f587cdb
commit 451be569e4fdc18e6155a54f53a16f7b3f587cdb Author: Mikael Morin <mik...@gcc.gnu.org> Date: Fri Apr 11 16:02:38 2025 +0200 Correction ICE 20231103-1 Diff: --- gcc/fortran/trans-decl.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index bf96da9f98c0..e1028f8da357 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -1046,11 +1046,23 @@ update_type_bounds (tree type, tree lbound[GFC_MAX_DIMENSIONS], || current_ubound != NULL_TREE || elt_type != TREE_TYPE (type)) { - tree new_type = build_variant_type_copy (type); + tree new_type = build_distinct_type_copy (type); TREE_TYPE (new_type) = elt_type; - TYPE_DOMAIN (new_type) = build_variant_type_copy (TYPE_DOMAIN (type)); - TYPE_MIN_VALUE (TYPE_DOMAIN (new_type)) = current_lbound; - TYPE_MAX_VALUE (TYPE_DOMAIN (new_type)) = current_ubound; + TYPE_DOMAIN (new_type) = build_distinct_type_copy (TYPE_DOMAIN (type)); + + tree new_lbound = current_lbound; + if (new_lbound == NULL_TREE) + new_lbound = TYPE_MIN_VALUE (TYPE_DOMAIN (type)); + TYPE_MIN_VALUE (TYPE_DOMAIN (new_type)) = new_lbound; + + tree new_ubound = current_ubound; + if (new_ubound == NULL_TREE) + new_ubound = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); + TYPE_MAX_VALUE (TYPE_DOMAIN (new_type)) = new_ubound; + + layout_type (TYPE_DOMAIN (new_type)); + layout_type (new_type); + type = new_type; }