]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Sync all for allocation and deallocation of coarrays.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 17 Dec 2020 18:58:49 +0000 (19:58 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Thu, 17 Dec 2020 18:58:49 +0000 (19:58 +0100)
gcc/fortran/ChangeLog:

* trans-stmt.c (coarray_alloc_p): New function.
(gfc_trans_allocate): If there are shared coarrays present,
call sync all.
(gfc_trans_deallocate): Likewise.

gcc/testsuite/ChangeLog:

* gfortran.dg/caf-shared/allocate_1.f90: New test.

gcc/fortran/trans-stmt.c
gcc/testsuite/gfortran.dg/caf-shared/allocate_1.f90 [new file with mode: 0644]

index 8db4333457c7d566023c10e282a0b0f9039322fc..1f656d43d88bca9622d86add012f85606d2c25f2 100644 (file)
@@ -6227,6 +6227,28 @@ allocate_get_initializer (gfc_code * code, gfc_expr * expr)
   return NULL;
 }
 
+/* Helper function - return true if a coarray is allcoated via this
+   statement.  */
+
+static bool
+coarray_alloc_p (gfc_code *code)
+{
+  if (code == NULL || code->op != EXEC_ALLOCATE)
+    return false;
+
+  for (gfc_alloc *al = code->ext.alloc.list; al != NULL; al = al->next)
+    {
+      gfc_ref *ref, *last;
+      for (ref = al->expr->ref, last = ref; ref; last = ref, ref = ref->next)
+       ;
+
+      ref = last;
+      if (ref && ref->type == REF_ARRAY && ref->u.ar.codimen)
+       return true;
+    }
+  return false;
+}
+
 /* Translate the ALLOCATE statement.  */
 
 tree
@@ -7235,6 +7257,12 @@ gfc_trans_allocate (gfc_code * code)
                                 zero_size);
       gfc_add_expr_to_block (&post, tmp);
     }
+  else if (flag_coarray == GFC_FCOARRAY_SHARED && coarray_alloc_p (code))
+    {
+      tmp = build_call_expr_loc (input_location, gfor_fndecl_cas_sync_all,
+                                1, null_pointer_node);
+      gfc_add_expr_to_block (&post, tmp);
+    }
 
   gfc_add_block_to_block (&block, &se.post);
   gfc_add_block_to_block (&block, &post);
@@ -7544,6 +7572,14 @@ gfc_trans_deallocate (gfc_code *code)
       gfc_add_modify (&block, se.expr, tmp);
     }
 
+  if (is_shared_coarray)
+    {
+      tmp = build_call_expr_loc (input_location, gfor_fndecl_cas_sync_all,
+                                1, null_pointer_node);
+      gfc_add_expr_to_block (&block, tmp);
+
+    }
+
   return gfc_finish_block (&block);
 }
 
diff --git a/gcc/testsuite/gfortran.dg/caf-shared/allocate_1.f90 b/gcc/testsuite/gfortran.dg/caf-shared/allocate_1.f90
new file mode 100644 (file)
index 0000000..0703b42
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+program main
+  real, allocatable :: a[:]
+  allocate (a[*])
+  deallocate (a)
+end program main
+! { dg-final { scan-tree-dump-times "_gfortran_cas_coarray_sync_all" 2 "original" } }
+