From c49eaa233a65b956f0bf07be4b6d65ae7e934143 Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Sat, 23 Apr 2011 12:26:38 +0200 Subject: [PATCH] re PR fortran/18918 (Eventually support Fortran 2008's coarrays [co-arrays]) 2011-04-23 Tobias Burnus PR fortran/18918 * module.c (mio_array_spec): Set as->cotype on reading. * resolve.c (resolve_allocate_expr): Fix allocating coarray components. 2011-04-23 Tobias Burnus PR fortran/18918 * gfortran.dg/coarray_19.f90: New. From-SVN: r172897 --- gcc/fortran/ChangeLog | 7 ++++++ gcc/fortran/module.c | 3 +++ gcc/fortran/resolve.c | 17 ++++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/coarray_19.f90 | 27 ++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray_19.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bbe8624a9ab..ec28bf4222d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2011-04-23 Tobias Burnus + + PR fortran/18918 + * module.c (mio_array_spec): Set as->cotype on reading. + * resolve.c (resolve_allocate_expr): Fix allocating coarray + components. + 2011-04-21 Thomas Koenig PR fortran/48405 diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 42e8e002692..fb8de0e39b6 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -2203,6 +2203,9 @@ mio_array_spec (gfc_array_spec **asp) mio_integer (&as->corank); as->type = MIO_NAME (array_type) (as->type, array_spec_types); + if (iomode == IO_INPUT && as->corank) + as->cotype = (as->type == AS_DEFERRED) ? AS_DEFERRED : AS_EXPLICIT; + for (i = 0; i < as->rank + as->corank; i++) { mio_expr (&as->lower[i]); diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index c1016121319..d7b95f51e17 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -6636,6 +6636,7 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code) { int i, pointer, allocatable, dimension, is_abstract; int codimension; + bool coindexed; symbol_attribute attr; gfc_ref *ref, *ref2; gfc_expr *e2; @@ -6693,18 +6694,32 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code) codimension = sym->attr.codimension; } + coindexed = false; + for (ref = e->ref; ref; ref2 = ref, ref = ref->next) { switch (ref->type) { case REF_ARRAY: + if (ref->u.ar.codimen > 0) + { + int n; + for (n = ref->u.ar.dimen; + n < ref->u.ar.dimen + ref->u.ar.codimen; n++) + if (ref->u.ar.dimen_type[n] != DIMEN_THIS_IMAGE) + { + coindexed = true; + break; + } + } + if (ref->next != NULL) pointer = 0; break; case REF_COMPONENT: /* F2008, C644. */ - if (gfc_is_coindexed (e)) + if (coindexed) { gfc_error ("Coindexed allocatable object at %L", &e->where); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 08aa6d48241..dfb9929fbb7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-04-23 Tobias Burnus + + PR fortran/18918 + * gfortran.dg/coarray_19.f90: New. + 2011-04-23 Jakub Jelinek PR c/48685 diff --git a/gcc/testsuite/gfortran.dg/coarray_19.f90 b/gcc/testsuite/gfortran.dg/coarray_19.f90 new file mode 100644 index 00000000000..cbb1dd20d8f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_19.f90 @@ -0,0 +1,27 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! +! PR fortran/18918 +! + +! Was failing before as the "x%a()[]" was +! regarded as coindexed +subroutine test2() + type t + integer, allocatable :: a(:)[:] + end type t + type(t), SAVE :: x + allocate(x%a(1)[*]) +end subroutine test2 + + +module m + integer, allocatable :: a(:)[:] +end module m + +! Was failing as "a" was allocatable but +! as->cotype was not AS_DEFERERED. +use m +end + +! { dg-final { cleanup-modules "m" } } -- 2.30.2