Hi all, here now the version of the patch that seems to be more complete.
Regtests ok on x86_64-pc-linux-gnu / F41. Ok for mainline and later backport to gcc-15? Regards, Andre On Fri, 27 Jun 2025 15:44:20 +0200 Andre Vehreschild <ve...@gmx.de> wrote: > I take this patch back. It seems to be incomplete. > > - Andre > > On Fri, 27 Jun 2025 14:45:36 +0200 > Andre Vehreschild <ve...@gmx.de> wrote: > > > Hi all, > > > > this patch fixes a reject valid when the coranks of two operands do not > > match and no coindex is given. I.e. when only an implicit this_image co-ref > > is used. > > > > Regtests ok on x86_64-pc-linux-gnu / F41. Ok for mainline? > > > > Regards, > > Andre > > -- Andre Vehreschild * Email: vehre ad gmx dot de
From 427ab489cefe47b801a29e0642d2eedc20474053 Mon Sep 17 00:00:00 2001 From: Andre Vehreschild <ve...@gcc.gnu.org> Date: Fri, 27 Jun 2025 14:39:13 +0200 Subject: [PATCH] Fortran: Fix non-conformable corank on this_image ref [PR120843] PR fortran/120843 gcc/fortran/ChangeLog: * resolve.cc (resolve_operator): Report inconsistent coranks only when not referencing this_image. (gfc_op_rank_conformable): Treat coranks as inconformable only when a coindex other then implicit this_image is used. gcc/testsuite/ChangeLog: * gfortran.dg/coarray/coindexed_6.f90: New test. --- gcc/fortran/resolve.cc | 7 ++++--- .../gfortran.dg/coarray/coindexed_6.f90 | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray/coindexed_6.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 58f7aee29c3..50a6fe7fc52 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -4828,7 +4828,8 @@ resolve_operator (gfc_expr *e) if (e->shape == NULL) e->shape = gfc_copy_shape (op2->shape, op2->corank); } - else + else if ((op1->ref && !gfc_ref_this_image (op1->ref)) + || (op2->ref && !gfc_ref_this_image (op2->ref))) { gfc_error ("Inconsistent coranks for operator at %L and %L", &op1->where, &op2->where); @@ -6070,8 +6071,8 @@ gfc_op_rank_conformable (gfc_expr *op1, gfc_expr *op2) gfc_expression_rank (op2); return (op1->rank == 0 || op2->rank == 0 || op1->rank == op2->rank) - && (op1->corank == 0 || op2->corank == 0 - || op1->corank == op2->corank); + && (op1->corank == 0 || op2->corank == 0 || op1->corank == op2->corank + || (!gfc_is_coindexed (op1) && !gfc_is_coindexed (op2))); } /* Resolve a variable expression. */ diff --git a/gcc/testsuite/gfortran.dg/coarray/coindexed_6.f90 b/gcc/testsuite/gfortran.dg/coarray/coindexed_6.f90 new file mode 100644 index 00000000000..8f5dcabb859 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/coindexed_6.f90 @@ -0,0 +1,17 @@ +!{ dg-do compile } + +! Check PR120843 is fixed + +program p + implicit none + + integer, allocatable :: arr(:,:) [:,:] + integer :: c[*] + + c = 7 + + allocate(arr(4,3)[2,*], source=6) + + if (arr(2,2)* c /= 42) stop 1 + +end program p -- 2.50.0