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

commit a53f7014d81ba07351ade3408332f3939cc0667e
Author: Mikael Morin <[email protected]>
Date:   Wed Aug 6 14:38:03 2025 +0200

    fortran: array descriptor: Factor dtype field access
    
    All the dtype fields accessors use the same pattern.  Introduce an internal
    function to factor the repeated code.
    
    gcc/fortran/ChangeLog:
    
            * trans-descriptor.cc (get_dtype_comp): New function.
            (conv_descriptor_rank, get_descriptor_version,
            conv_descriptor_elem_len, conv_descriptor_type): Use it.

Diff:
---
 gcc/fortran/trans-descriptor.cc | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index cbf0f86bfdb1..ade7e9bed227 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -202,12 +202,17 @@ gfc_conv_descriptor_span_set (stmtblock_t *block, tree 
desc, tree value)
 /* Return a reference to the rank of array descriptor DESC.  */
 
 static tree
-conv_descriptor_rank (tree desc)
+get_dtype_comp (tree desc, unsigned field_idx, tree type = NULL_TREE)
 {
-  tree dtype;
+  tree dtype_ref = conv_descriptor_dtype (desc);
+  return get_ref_comp (dtype_ref, field_idx, type);
+}
+
 
-  dtype = conv_descriptor_dtype (desc);
-  return get_ref_comp (dtype, GFC_DTYPE_RANK, signed_char_type_node);
+static tree
+conv_descriptor_rank (tree desc)
+{
+  return get_dtype_comp (desc, GFC_DTYPE_RANK, signed_char_type_node);
 }
 
 /* Return the rank of the array descriptor DESC.  */
@@ -243,10 +248,7 @@ gfc_conv_descriptor_rank_set (stmtblock_t *block, tree 
desc, int value)
 static tree
 conv_descriptor_version (tree desc)
 {
-  tree dtype;
-
-  dtype = conv_descriptor_dtype (desc);
-  return get_ref_comp (dtype, GFC_DTYPE_VERSION, integer_type_node);
+  return get_dtype_comp (desc, GFC_DTYPE_VERSION, integer_type_node);
 }
 
 /* Return the value of descriptor DESC's format version.  */
@@ -274,10 +276,7 @@ gfc_conv_descriptor_version_set (stmtblock_t *block, tree 
desc, tree value)
 static tree
 conv_descriptor_elem_len (tree desc)
 {
-  tree dtype;
-
-  dtype = conv_descriptor_dtype (desc);
-  return get_ref_comp (dtype, GFC_DTYPE_ELEM_LEN, size_type_node);
+  return get_dtype_comp (desc, GFC_DTYPE_ELEM_LEN, size_type_node);
 }
 
 /* Return the descriptor DESC's array element size in bytes.  */
@@ -306,10 +305,7 @@ gfc_conv_descriptor_elem_len_set (stmtblock_t *block, tree 
desc, tree value)
 static tree
 conv_descriptor_type (tree desc)
 {
-  tree dtype;
-
-  dtype = conv_descriptor_dtype (desc);
-  return get_ref_comp (dtype, GFC_DTYPE_TYPE, signed_char_type_node);
+  return get_dtype_comp (desc, GFC_DTYPE_TYPE, signed_char_type_node);
 }
 
 /* Return the value of the type discriminator of the array descriptor DESC.  */

Reply via email to