Hi all, hi Thomas,

On 02.02.21 18:15, Tobias Burnus wrote:
I think I will do a combination: If 'identical' is true, I think I
cannot remove it. If it is false, it can be identical or nonoverlapping
– which makes sense.

Well, it turned out that coarray scalars did not work; for them,
the array ref consists only of the coindexed access: falling through
then triggered as fin_dep == GFC_DEP_ERROR.

To be more careful, I also removed the 'identical &&' check such that
the first loop is now always triggered if coarray != SINGLE not only
if identical – I am not sure whether it is really needed or whether
falling though is the better solution (with updating the comment).

I would be happy if someone could carefully check the logic –
in the details, it is rather confusing.

OK?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
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

Reply via email to