https://gcc.gnu.org/g:c15376d8658c5bc6462ad1a9d89954024876c9a9

commit c15376d8658c5bc6462ad1a9d89954024876c9a9
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 c0d9622b4ee1..bf0f244b9900 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1048,11 +1048,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;
     }

Reply via email to