From 2ccd6f727633d25730154efd7094900d24bf6544 Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Wed, 11 Dec 2013 15:02:44 +0100 Subject: [PATCH] re PR fortran/58916 ([F03] Allocation of scalar with array source not rejected) 2013-12-11 Janus Weil PR fortran/58916 * resolve.c (conformable_arrays): Treat scalar 'e2'. (resolve_allocate_expr): Check rank also for unlimited-polymorphic variables. 2013-12-11 Janus Weil PR fortran/58916 * gfortran.dg/allocate_with_source_4.f90: New. From-SVN: r205894 --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/resolve.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/allocate_with_source_4.f90 | 12 ++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/allocate_with_source_4.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index cb87dd05c1a..cd4b38556be 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2013-12-11 Janus Weil + + PR fortran/58916 + * resolve.c (conformable_arrays): Treat scalar 'e2'. + (resolve_allocate_expr): Check rank also for unlimited-polymorphic + variables. + 2013-12-10 Janus Weil PR fortran/35831 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ea4632473fc..db2f5eb705a 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -6597,7 +6597,8 @@ conformable_arrays (gfc_expr *e1, gfc_expr *e2) for (tail = e2->ref; tail && tail->next; tail = tail->next); /* First compare rank. */ - if (tail && e1->rank != tail->u.ar.as->rank) + if ((tail && e1->rank != tail->u.ar.as->rank) + || (!tail && e1->rank != e2->rank)) { gfc_error ("Source-expr at %L must be scalar or have the " "same rank as the allocate-object at %L", @@ -6794,8 +6795,7 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code) } /* Check F03:C632 and restriction following Note 6.18. */ - if (code->expr3->rank > 0 && !unlimited - && !conformable_arrays (code->expr3, e)) + if (code->expr3->rank > 0 && !conformable_arrays (code->expr3, e)) goto failure; /* Check F03:C633. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b7e72deb7b8..db4f10167d0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-12-11 Janus Weil + + PR fortran/58916 + * gfortran.dg/allocate_with_source_4.f90: New. + 2013-12-11 Jakub Jelinek PR tree-optimization/59417 diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_4.f90 b/gcc/testsuite/gfortran.dg/allocate_with_source_4.f90 new file mode 100644 index 00000000000..dcd42a7981a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_source_4.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! +! PR 58916: [F03] Allocation of scalar with array source not rejected +! +! Contributed by Vladimir Fuka + + class(*), allocatable :: a1 + real, allocatable :: a2 + real b(1) + allocate(a1, source=b) ! { dg-error "must be scalar or have the same rank" } + allocate(a2, source=b) ! { dg-error "must be scalar or have the same rank" } +end