Fortran: Fix coarray handling for gfc_dep_resolver [PR99010] Check failed if identical = false was requested or for -fcoarray=single if an array ref was for a coindexed scalar. gcc/fortran/ChangeLog: PR fortran/99010 * dependency.c (gfc_dep_resolver): Fix coarray handling. gcc/testsuite/ChangeLog: PR fortran/99010 * gfortran.dg/coarray/array_temporary-1.f90: New test. gcc/fortran/dependency.c | 14 +++++++++++--- gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 | 13 +++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/dependency.c b/gcc/fortran/dependency.c index 5de3b2cf520..e1336e1c654 100644 --- a/gcc/fortran/dependency.c +++ b/gcc/fortran/dependency.c @@ -2145,9 +2145,9 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse, case REF_ARRAY: /* Coarrays: If there is a coindex, either the image differs and there is no overlap or the image is the same - then the normal analysis - applies. Hence, return early only if 'identical' is required and - either ref is coindexed and more than one image can exist. */ - if (identical && flag_coarray != GFC_FCOARRAY_SINGLE + applies. Hence, return early if either ref is coindexed and more + than one image can exist. */ + if (flag_coarray != GFC_FCOARRAY_SINGLE && ((lref->u.ar.codimen && lref->u.ar.dimen_type[lref->u.ar.dimen] != DIMEN_THIS_IMAGE) @@ -2155,6 +2155,14 @@ gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse, && lref->u.ar.dimen_type[lref->u.ar.dimen] != DIMEN_THIS_IMAGE))) return 1; + if (lref->u.ar.dimen == 0 || rref->u.ar.dimen == 0) + { + /* Coindexed scalar coarray with GFC_FCOARRAY_SINGLE. */ + if (lref->u.ar.dimen || rref->u.ar.dimen) + return 1; /* Just to be sure. */ + fin_dep = GFC_DEP_EQUAL; + break; + } if (ref_same_as_full_array (lref, rref)) return identical; diff --git a/gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 b/gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 new file mode 100644 index 00000000000..454929cf53b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 @@ -0,0 +1,13 @@ +! PR fortran/99010 +! +! Follow-up to PR fortran/98913 +! +! Contributed by G. Steinmetz +! +program p + integer :: x[*] + x = this_image() + if ( this_image() == 2 ) then + x = x[1] + end if +end