https://gcc.gnu.org/g:6a7e4e64c867f440ba444dad9b4bf8af814b617f

commit 6a7e4e64c867f440ba444dad9b4bf8af814b617f
Author: Mikael Morin <[email protected]>
Date:   Sat Sep 27 21:31:30 2025 +0200

    Correction régression associate_33.f03

Diff:
---
 gcc/fortran/trans-array.cc | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 59680c633512..bcb8f6bc93c4 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3919,10 +3919,19 @@ build_array_ref (gfc_se *se, tree array, tree ref_base, 
gfc_expr *expr,
       {
        tree offset = fold_convert_loc (input_location, size_type_node,
                                        index);
+       tree ptr = ref_base;
+       if (TREE_CODE (ptr) == INDIRECT_REF
+           && TREE_CODE (TREE_TYPE (ptr)) == ARRAY_TYPE)
+         ptr = TREE_OPERAND (ptr, 0);
+       gcc_assert (TREE_CODE (TREE_TYPE (ptr)) == POINTER_TYPE);
+       tree data_type = GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (array));
+       ptr = fold_convert_loc (input_location, data_type, ptr);
+       tree ptr_type = TREE_TYPE (ptr);
+       gcc_assert (TREE_CODE (ptr_type) == POINTER_TYPE);
+       if (TREE_CODE (TREE_TYPE (ptr_type)) == ARRAY_TYPE)
+         ptr_type = build_pointer_type (TREE_TYPE (TREE_TYPE (ptr_type)));
        tree p = fold_build2_loc (input_location, POINTER_PLUS_EXPR,
-                                 TREE_TYPE (ref_base), ref_base, offset);
-       p = fold_convert_loc (input_location,
-                             GFC_TYPE_ARRAY_DATAPTR_TYPE (TREE_TYPE (array)), 
p);
+                                 ptr_type, ptr, offset);
        se->expr = build_fold_indirect_ref_loc (input_location, p);
       }
       break;

Reply via email to