https://gcc.gnu.org/g:7d364c0b1e0d1d518aa9f56eb6eade02cacfb7d2

commit 7d364c0b1e0d1d518aa9f56eb6eade02cacfb7d2
Author: Mikael Morin <[email protected]>
Date:   Fri Jun 26 17:23:09 2026 +0200

    Correction régressions coarray

Diff:
---
 gcc/fortran/trans-intrinsic.cc | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 8cb30854a36b..b98e6f00cd64 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -1911,7 +1911,9 @@ trans_this_image (gfc_se * se, gfc_expr *expr)
                                  build_int_cst (TREE_TYPE (dim_arg), 1));
          tmp = gfc_rank_cst[GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc))];
          tmp = fold_build2_loc (input_location, GT_EXPR, logical_type_node,
-                                dim_arg, tmp);
+                                dim_arg,
+                                fold_convert_loc (input_location,
+                                                  TREE_TYPE (dim_arg), tmp));
          cond = fold_build2_loc (input_location, TRUTH_ORIF_EXPR,
                                  logical_type_node, cond, tmp);
          gfc_trans_runtime_check (true, false, cond, &se->pre, &expr->where,
@@ -2489,7 +2491,9 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, 
enum gfc_isym_id op)
          else
            tmp = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc))];
           tmp = fold_build2_loc (input_location, GE_EXPR, logical_type_node,
-                                bound, fold_convert(TREE_TYPE (bound), tmp));
+                                bound,
+                                fold_convert_loc (input_location,
+                                                  TREE_TYPE (bound), tmp));
           cond = fold_build2_loc (input_location, TRUTH_ORIF_EXPR,
                                  logical_type_node, cond, tmp);
           gfc_trans_runtime_check (true, false, cond, &se->pre, &expr->where,
@@ -2658,8 +2662,11 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
       gcc_assert (se->ss->info->expr == expr);
 
       bound = se->loop->loopvar[0];
+      tree rank = gfc_rank_cst[arg->expr->rank];
       bound = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type,
-                              bound, gfc_rank_cst[arg->expr->rank]);
+                              bound,
+                              fold_convert_loc (input_location,
+                                                TREE_TYPE (bound), rank));
       gfc_advance_se_ss_chain (se);
     }
   else if (expr->value.function.isym->id == GFC_ISYM_COSHAPE)
@@ -2686,9 +2693,11 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
          bound = gfc_evaluate_now (bound, &se->pre);
          cond = fold_build2_loc (input_location, LT_EXPR, logical_type_node,
                                  bound, build_int_cst (TREE_TYPE (bound), 1));
-         tmp = gfc_rank_cst[GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc))];
+         tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc))];
          tmp = fold_build2_loc (input_location, GT_EXPR, logical_type_node,
-                                bound, tmp);
+                                bound,
+                                fold_convert_loc (input_location,
+                                                  TREE_TYPE (bound), rank));
          cond = fold_build2_loc (input_location, TRUTH_ORIF_EXPR,
                                  logical_type_node, cond, tmp);
          gfc_trans_runtime_check (true, false, cond, &se->pre, &expr->where,
@@ -2706,9 +2715,14 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
        case 1:
          break;
        default:
-         bound = fold_build2_loc (input_location, PLUS_EXPR,
-                                  gfc_array_index_type, bound,
-                                  gfc_rank_cst[arg->expr->rank - 1]);
+         {
+           tree rank = gfc_rank_cst[arg->expr->rank - 1];
+           bound = fold_build2_loc (input_location, PLUS_EXPR,
+                                    gfc_array_index_type, bound,
+                                    fold_convert_loc (input_location,
+                                                      TREE_TYPE (bound),
+                                                      rank));
+         }
        }
     }

Reply via email to