diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2020-12-17 19:58:49 +0100 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2020-12-17 19:58:49 +0100 |
commit | bbf09c0aa07e56fe79710d3427311c6e73791fba (patch) | |
tree | 46f9f3f2cfbd76b60198cace789ccc075630eef5 | |
parent | d91352b42efcb2a81039ab1911d4fda414143ddb (diff) | |
download | gcc-bbf09c0aa07e56fe79710d3427311c6e73791fba.zip gcc-bbf09c0aa07e56fe79710d3427311c6e73791fba.tar.gz gcc-bbf09c0aa07e56fe79710d3427311c6e73791fba.tar.bz2 |
Sync all for allocation and deallocation of coarrays.
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.
-rw-r--r-- | gcc/fortran/trans-stmt.c | 36 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/caf-shared/allocate_1.f90 | 9 |
2 files changed, 45 insertions, 0 deletions
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 8db4333..1f656d4 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -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 index 0000000..0703b42 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/caf-shared/allocate_1.f90 @@ -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" } } + |