https://gcc.gnu.org/g:759138ebeac55bc74a73ae36a5a1551981ddf357

commit 759138ebeac55bc74a73ae36a5a1551981ddf357
Author: Mikael Morin <[email protected]>
Date:   Wed Aug 6 14:41:41 2025 +0200

    fortran: array descriptor: Factor dim subfields type check
    
    All the internal accessors to generate component references to subfields of
    dim elements have the same assert checking the returned component type.
    Add a type argument to factor that check.
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (gfc_conv_descriptor_subfield): Add an
            optional type argument to pass to get_ref_comp and rename to ...
            (get_descr_dim_comp): ... this.
            (get_descriptor_stride, get_descriptor_lbound,
            get_descriptor_ubound): Pass a type argument and remove the assert
            checking the type.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index ade7e9bed227..71156b7867a0 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -462,10 +462,11 @@ gfc_conv_descriptor_token_set (stmtblock_t *block, tree 
desc, tree value)
 
 
 static tree
-gfc_conv_descriptor_subfield (tree desc, tree dim, unsigned field_idx)
+get_descr_dim_comp (tree desc, tree dim, unsigned field_idx,
+                   tree type = NULL_TREE)
 {
   tree tmp = conv_descriptor_dimension (desc, dim);
-  return get_ref_comp (tmp, field_idx);
+  return get_ref_comp (tmp, field_idx, type);
 }
 
 
@@ -475,9 +476,7 @@ gfc_conv_descriptor_subfield (tree desc, tree dim, unsigned 
field_idx)
 static tree
 get_descriptor_stride (tree desc, tree dim)
 {
-  tree field = gfc_conv_descriptor_subfield (desc, dim, STRIDE_SUBFIELD);
-  gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
-  return field;
+  return get_descr_dim_comp (desc, dim, STRIDE_SUBFIELD, gfc_array_index_type);
 }
 
 /* Return the value of the stride for the (zero-based) dimension DIM of the
@@ -518,9 +517,7 @@ gfc_conv_descriptor_stride_set (stmtblock_t *block, tree 
desc,
 static tree
 get_descriptor_lbound (tree desc, tree dim)
 {
-  tree field = gfc_conv_descriptor_subfield (desc, dim, LBOUND_SUBFIELD);
-  gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
-  return field;
+  return get_descr_dim_comp (desc, dim, LBOUND_SUBFIELD, gfc_array_index_type);
 }
 
 /* Return the value of the lower bound for the (zero-based) dimension DIM of 
the
@@ -550,9 +547,7 @@ gfc_conv_descriptor_lbound_set (stmtblock_t *block, tree 
desc,
 static tree
 get_descriptor_ubound (tree desc, tree dim)
 {
-  tree field = gfc_conv_descriptor_subfield (desc, dim, UBOUND_SUBFIELD);
-  gcc_assert (TREE_TYPE (field) == gfc_array_index_type);
-  return field;
+  return get_descr_dim_comp (desc, dim, UBOUND_SUBFIELD, gfc_array_index_type);
 }
 
 /* Return the value of the upper bound for the (zero-based) dimension DIM of 
the

Reply via email to