Fortran: Fix coarray handling for gfc_dep_resolver [PR99010]
authorTobias Burnus <tobias@codesourcery.com>
Fri, 19 Feb 2021 17:07:26 +0000 (18:07 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 19 Feb 2021 17:07:26 +0000 (18:07 +0100)
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
gcc/testsuite/gfortran.dg/coarray/array_temporary-1.f90 [new file with mode: 0644]

index 5de3b2cf5208846b9aa17d02140822ee06436436..e1336e1c65458b4606c283f01051a3269b828487 100644 (file)
@@ -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 (file)
index 0000000..454929c
--- /dev/null
@@ -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