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

commit f8e211c1d191e27d1b9ff4206cdcca98f6ab1654
Author: Mikael Morin <[email protected]>
Date:   Mon Nov 9 22:46:20 2026 +0100

    Correction partielle reduce_1

Diff:
---
 gcc/fortran/trans-descriptor.cc |  2 ++
 libgfortran/intrinsics/reduce.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/trans-descriptor.cc b/gcc/fortran/trans-descriptor.cc
index 2139cd9fc311..4dc2843a04b2 100644
--- a/gcc/fortran/trans-descriptor.cc
+++ b/gcc/fortran/trans-descriptor.cc
@@ -798,6 +798,8 @@ gfc_create_unallocated_library_result_descriptor 
(stmtblock_t *block,
     dtype = gfc_get_dtype (TREE_TYPE (source_descr));
 
   gfc_conv_descriptor_dtype_set (block, source_descr, dtype);
+  gfc_conv_descriptor_span_set (block, source_descr,
+                               gfc_conv_descriptor_span_get (source_descr));
 
   tree res_desc = gfc_evaluate_now (source_descr, block);
   gfc_conv_descriptor_data_set (block, res_desc, null_pointer_node);
diff --git a/libgfortran/intrinsics/reduce.c b/libgfortran/intrinsics/reduce.c
index 071d9486d119..9449e144c19a 100644
--- a/libgfortran/intrinsics/reduce.c
+++ b/libgfortran/intrinsics/reduce.c
@@ -94,7 +94,7 @@ reduce (parray *ret,
      painless by the use of pointer arithmetic throughout (except for MASK,
      whose type is known.  */
   ext0 = ext1 = ext2 = 1;
-  str0 = str1 = str2 = 1;
+  str0 = str1 = str2 = elem_len;
 
   scalar_result = (!dim_present && array_rank > 1) || array_rank == 1;
 
@@ -103,7 +103,6 @@ reduce (parray *ret,
     {
       /* Obtain the shape of the reshaped ARRAY.  */
       ext = GFC_DESCRIPTOR_EXTENT (array,i);
-      str = GFC_DESCRIPTOR_STRIDE (array,i);
 
       if (mask_present && (ext != GFC_DESCRIPTOR_EXTENT (mask, i)))
        {
@@ -135,11 +134,11 @@ reduce (parray *ret,
 
   if (!scalar_result)
     {
-      str1 = GFC_DESCRIPTOR_STRIDE (array, dimen_m1);
+      str1 = GFC_DESCRIPTOR_STRIDE_BYTES (array, dimen_m1);
       if (dimen < array_rank)
-       str2 = GFC_DESCRIPTOR_STRIDE (array, dimen);
+       str2 = GFC_DESCRIPTOR_STRIDE_BYTES (array, dimen);
       else
-       str2 = 1;
+       str2 = elem_len;
     }
 
   /* Allocate the result data, the result buffer and zero.  */
@@ -160,7 +159,7 @@ reduce (parray *ret,
          started = (mask_present && maskR) || !mask_present;
 
          buffer_ptr = array->base_addr
-                       + (size_t)((idx0 * str0 + idx2 * str2) * elem_len);
+                       + (size_t)((idx0 * str0 + idx2 * str2));
 
          /* Start the iteration over the second dimension of ARRAY.  */
          for (idx1 = 1; idx1 < ext1; idx1++)
@@ -174,7 +173,7 @@ reduce (parray *ret,
 
              array_ptr = array->base_addr
                          + (size_t)((idx0 * str0 + idx1 * str1
-                                     + idx2 * str2) * elem_len);
+                                     + idx2 * str2));
              if (!started)
                {
                  if (mask_present && maskR)
@@ -198,7 +197,7 @@ reduce (parray *ret,
             result. If this result element is empty emit an error or, if
             available, set to identity. Note that str1 is paired with idx2
             here because the result skips a dimension.  */
-         res = ret->base_addr + (size_t)((idx0 * str0 + idx2 * str1) * 
elem_len);
+         res = ret->base_addr + (size_t)((idx0 * str0 + idx2 * str1));
          if (started)
            {
              operation (buffer_ptr, NULL, res);

Reply via email to