From 84f1346bb98aa6b0a24e89a86cd4f0c6829c011a Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Wed, 6 Mar 2019 20:28:22 +0000 Subject: [PATCH] re PR fortran/72714 ([Coarray] ICE in gfc_array_init_size, at fortran/trans-array.c:5235) 2019-03-06 Thomas Koenig PR fortran/72714 Backport from trunk * resolve.c (resolve_allocate_expr): Add some tests for coarrays. 2019-03-06 Thomas Koenig PR fortran/72714 Backport from trunk * gfortran.dg/coarray_allocate_11.f90: New test. From-SVN: r269441 --- gcc/fortran/ChangeLog | 6 +++ gcc/fortran/resolve.c | 53 ++++++++++++++++--- gcc/testsuite/ChangeLog | 6 +++ .../gfortran.dg/coarray_allocate_11.f90 | 15 ++++++ 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c987e1ba15d9..37b651ad812c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-03-06 Thomas Koenig + + PR fortran/72714 + Backport from trunk + * resolve.c (resolve_allocate_expr): Add some tests for coarrays. + 2019-03-03 Harald Anlauf Steven G. Kargl diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 1a3bedf23f21..517d5a7b1754 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -7431,13 +7431,54 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec) if (codimension) for (i = ar->dimen; i < ar->dimen + ar->codimen; i++) - if (ar->dimen_type[i] == DIMEN_THIS_IMAGE) - { - gfc_error ("Coarray specification required in ALLOCATE statement " - "at %L", &e->where); - goto failure; - } + { + switch (ar->dimen_type[i]) + { + case DIMEN_THIS_IMAGE: + gfc_error ("Coarray specification required in ALLOCATE statement " + "at %L", &e->where); + goto failure; + + case DIMEN_RANGE: + if (ar->start[i] == 0 || ar->end[i] == 0) + { + /* If ar->stride[i] is NULL, we issued a previous error. */ + if (ar->stride[i] == NULL) + gfc_error ("Bad array specification in ALLOCATE statement " + "at %L", &e->where); + goto failure; + } + else if (gfc_dep_compare_expr (ar->start[i], ar->end[i]) == 1) + { + gfc_error ("Upper cobound is less than lower cobound at %L", + &ar->start[i]->where); + goto failure; + } + break; + + case DIMEN_ELEMENT: + if (ar->start[i]->expr_type == EXPR_CONSTANT) + { + gcc_assert (ar->start[i]->ts.type == BT_INTEGER); + if (mpz_cmp_si (ar->start[i]->value.integer, 1) < 0) + { + gfc_error ("Upper cobound is less than lower cobound " + " of 1 at %L", &ar->start[i]->where); + goto failure; + } + } + break; + + case DIMEN_STAR: + break; + default: + gfc_error ("Bad array specification in ALLOCATE statement at %L", + &e->where); + goto failure; + + } + } for (i = 0; i < ar->dimen; i++) { if (ar->type == AR_ELEMENT || ar->type == AR_FULL) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 257e2823dae1..4514739248b6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-03-06 Thomas Koenig + + PR fortran/72714 + Backport from trunk + * gfortran.dg/coarray_allocate_11.f90: New test. + 2019-03-03 Harald Anlauf Backport from trunk diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 b/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 new file mode 100644 index 000000000000..0e806f0955b3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! { dg-additional-options -fcoarray=single } +program p + integer, allocatable :: z[:,:] + integer :: i + allocate (z[1:,*]) ! { dg-error "Bad array specification in ALLOCATE statement" } + allocate (z[:2,*]) ! { dg-error "Bad array specification in ALLOCATE statement" } + allocate (z[2:1,*]) ! { dg-error "Upper cobound is less than lower cobound" } + allocate (z[:0,*]) ! { dg-error "Bad array specification in ALLOCATE statement" } + allocate (z[0,*]) ! { dg-error "Upper cobound is less than lower cobound" } + allocate (z[1,*]) ! This is OK + allocate (z[1:1,*]) ! This is OK + allocate (z[i:i,*]) ! This is OK + allocate (z[i:i-1,*]) ! { dg-error "Upper cobound is less than lower cobound" } +end -- 2.47.2