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

commit f8c2b7ef2a61e48a8be35caec9aa9e6ba3b3741b
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Sat Apr 12 15:44:20 2025 +0200

    Correction ICE aliasing_complex_pointer

Diff:
---
 gcc/fortran/trans-array.cc      | 25 +++++++++++++------------
 gcc/fortran/trans-descriptor.cc | 12 +-----------
 gcc/fortran/trans-types.cc      | 21 +++++++++++++++++++++
 gcc/fortran/trans-types.h       |  2 ++
 4 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 9f17a6d8eac7..fa84f007bee5 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1045,6 +1045,7 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
          info->start[dim] = gfc_index_zero_node;
          info->end[dim] = gfc_index_zero_node;
          info->stride[dim] = gfc_index_one_node;
+         info->lbound[dim] = gfc_index_zero_node;
        }
     }
 
@@ -1189,7 +1190,7 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
     {
       for (n = 0; n < total_dim; n++)
        {
-         spacing[n] = size;
+         info->spacing[n] = spacing[n] = size;
 
          tree extent = to[n];
          if (!shift_bounds && !integer_zerop (from[n]))
@@ -3480,7 +3481,7 @@ non_negative_strides_array_p (tree expr)
 
 
 static tree
-build_array_ref (tree descriptor, tree array, tree index,
+build_array_ref (tree array, tree index,
                 bool non_negative_stride, tree lbound, tree spacing,
                 const vec<tree> * array_type_domains)
 {
@@ -3489,24 +3490,21 @@ build_array_ref (tree descriptor, tree array, tree 
index,
     elt_type = TREE_TYPE (TREE_TYPE (array));
   else
     {
-      tree desc_type = TREE_TYPE (descriptor);
-      tree core_type = TREE_TYPE (GFC_TYPE_ARRAY_DATAPTR_TYPE (desc_type));
+      tree core_type = TREE_TYPE (array);
 
       unsigned j;
       tree *dom_p;
       FOR_EACH_VEC_ELT (*array_type_domains, j, dom_p)
        {
-         gcc_assert (GFC_ARRAY_TYPE_P (core_type)
+         gcc_assert (TREE_CODE (core_type) == ARRAY_TYPE
                      && TYPE_DOMAIN (core_type) == *dom_p);
          core_type = TREE_TYPE (core_type);
        }
 
-      core_type = TREE_TYPE (core_type);
-
-      tree elt_type = core_type;
+      elt_type = TREE_TYPE (core_type);
 
       FOR_EACH_VEC_ELT_REVERSE (*array_type_domains, j, dom_p)
-       elt_type = build_array_type (elt_type, *dom_p);
+       elt_type = gfc_build_incomplete_array_type (elt_type, *dom_p);
     }
 
   return gfc_build_array_ref (elt_type, array, index, non_negative_stride,
@@ -3827,7 +3825,7 @@ add_array_index (stmtblock_t *pblock, gfc_loopinfo *loop, 
gfc_ss *ss,
                             || ss_type == GFC_SS_CONSTRUCTOR
                             || ss_type == GFC_SS_INTRINSIC
                             || non_negative_strides_array_p (info->descriptor);
-  return build_array_ref (info->descriptor, array, index, non_negative_stride,
+  return build_array_ref (array, index, non_negative_stride,
                          info->lbound[array_dim], info->spacing[array_dim],
                          array_type_domains);
 }
@@ -4609,7 +4607,10 @@ done:
            for (n = 0; n < GFC_MAX_DIMENSIONS; n++)
              if (info->subscript[n]
                  && info->subscript[n]->info->type == GFC_SS_SCALAR)
-               conv_evaluate_lbound (&outer_loop->pre, ss, n);
+               {
+                 conv_array_spacing (&outer_loop->pre, ss, n);
+                 conv_evaluate_lbound (&outer_loop->pre, ss, n);
+               }
          break;
 
        case GFC_SS_INTRINSIC:
@@ -6887,7 +6888,7 @@ gfc_get_dataptr_offset (stmtblock_t *block, tree parm, 
tree desc,
 
   for (int i = GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc)) - 1; i >= 0; i--)
     {
-      array = build_array_ref (desc, array, gfc_index_zero_node,
+      array = build_array_ref (array, gfc_index_zero_node,
                               non_negative_strides, gfc_index_zero_node,
                               gfc_conv_array_spacing (desc, i), nullptr);
     }
diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 88062e3b8b3a..190311675198 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -982,17 +982,7 @@ gfc_build_desc_array_type (tree desc_type, tree etype, int 
dimen, tree * lbound,
 
       tree index_type = build_range_type (gfc_array_index_type, lower, upper);
 
-      tree elt_type = type;
-      type = make_node (ARRAY_TYPE);
-      TREE_TYPE (type) = elt_type;
-      TYPE_DOMAIN (type) = index_type;
-      TYPE_ADDR_SPACE (type) = TYPE_ADDR_SPACE (elt_type);
-
-      /* Set TYPE_STRUCTURAL_EQUALITY_P.  */
-      if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
-         || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
-         || in_lto_p)
-       SET_TYPE_STRUCTURAL_EQUALITY (type);
+      type = gfc_build_incomplete_array_type (type, index_type);
     }
 
   return type;
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index b02215f6620d..2eed2f010819 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -4271,4 +4271,25 @@ gfc_get_cfi_type (int dimen, bool restricted)
   return CFI_cdesc_t;
 }
 
+
+/* Variant of build_array_type that doesn't call layout_type.  */
+
+tree
+gfc_build_incomplete_array_type (tree elt_type, tree index_type)
+{
+  tree type = make_node (ARRAY_TYPE);
+  TREE_TYPE (type) = elt_type;
+  TYPE_DOMAIN (type) = index_type;
+  TYPE_ADDR_SPACE (type) = TYPE_ADDR_SPACE (elt_type);
+
+  /* Set TYPE_STRUCTURAL_EQUALITY_P.  */
+  if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
+      || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))
+      || in_lto_p)
+    SET_TYPE_STRUCTURAL_EQUALITY (type);
+
+  return type;
+}
+
+
 #include "gt-fortran-trans-types.h"
diff --git a/gcc/fortran/trans-types.h b/gcc/fortran/trans-types.h
index 1f1281524507..5f4da9202d78 100644
--- a/gcc/fortran/trans-types.h
+++ b/gcc/fortran/trans-types.h
@@ -123,4 +123,6 @@ tree gfc_get_dtype (tree, int *rank = NULL);
 tree gfc_get_caf_vector_type (int dim);
 tree gfc_get_caf_reference_type ();
 
+tree gfc_build_incomplete_array_type (tree, tree);
+
 #endif

Reply via email to