From 2fe6eed9d13406aa09a14dea82c37280fb3aa6c0 Mon Sep 17 00:00:00 2001 From: tkoenig Date: Wed, 10 May 2006 18:26:51 +0000 Subject: [PATCH] 2005-05-10 Thomas Koenig PR fortran/27470 * trans-array.c(gfc_array_allocate): If ref->next exists that is if there is a statement like ALLOCATE(foo%bar(2)), F95 rules require that bar should be a pointer. 2005-05-10 Thomas Koenig PR fortran/27470 * gfortran.dg/multiple_allocation_2.f90: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113680 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/trans-array.c | 16 +++++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/multiple_allocation_2.f90 | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/multiple_allocation_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 32cadb2f52c..9fbde4d3b22 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2005-05-10 Thomas Koenig + + PR fortran/27470 + * trans-array.c(gfc_array_allocate): If ref->next exists + that is if there is a statement like ALLOCATE(foo%bar(2)), + F95 rules require that bar should be a pointer. + 2006-05-10 Francois-Xavier Coudert PR fortran/20460 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index a620bff67f0..7e9d5a65ef0 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -3068,9 +3068,20 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree pstat) gfc_expr **upper; gfc_ref *ref; int allocatable_array; + int must_be_pointer; ref = expr->ref; + /* In Fortran 95, components can only contain pointers, so that, + in ALLOCATE (foo%bar(2)), bar must be a pointer component. + We test this by checking for ref->next. + An implementation of TR 15581 would need to change this. */ + + if (ref) + must_be_pointer = ref->next != NULL; + else + must_be_pointer = 0; + /* Find the last reference in the chain. */ while (ref && ref->next != NULL) { @@ -3113,7 +3124,10 @@ gfc_array_allocate (gfc_se * se, gfc_expr * expr, tree pstat) tmp = gfc_conv_descriptor_data_addr (se->expr); pointer = gfc_evaluate_now (tmp, &se->pre); - allocatable_array = expr->symtree->n.sym->attr.allocatable; + if (must_be_pointer) + allocatable_array = 0; + else + allocatable_array = expr->symtree->n.sym->attr.allocatable; if (TYPE_PRECISION (gfc_array_index_type) == 32) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a7eace8726f..872070dccdf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-05-10 Thomas Koenig + + PR fortran/27470 + * gfortran.dg/multiple_allocation_2.f90: New test case. + 2006-05-10 Kazu Hirata * gcc.target/arm/pr27387.C: Fix a comment typo. diff --git a/gcc/testsuite/gfortran.dg/multiple_allocation_2.f90 b/gcc/testsuite/gfortran.dg/multiple_allocation_2.f90 new file mode 100644 index 00000000000..617405be110 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/multiple_allocation_2.f90 @@ -0,0 +1,16 @@ +! { dg-do run } +! PR 27470: This used fail because of confusion between +! mol (allocatable) and mol(1)%array(:) (pointer). +! Derived from a test case by FX Coudert. +PROGRAM MAIN + TYPE foo + INTEGER, DIMENSION(:), POINTER :: array + END TYPE foo + + type(foo),allocatable,dimension(:) :: mol + + ALLOCATE (mol(1)) + ALLOCATE (mol(1)%array(5)) + ALLOCATE (mol(1)%array(5)) + + END -- 2.11.4.GIT