This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR35470 - Valid pointer assigment code gives compilation errors
- From: "Paul Richard Thomas" <paul dot richard dot thomas at gmail dot com>
- To: "Fortran List" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 16 Mar 2008 18:45:37 +0100
- Subject: [Patch, fortran] PR35470 - Valid pointer assigment code gives compilation errors
- References: <339c37f20803161040n6be05928o56f688a9f6fba340@mail.gmail.com>
:ADDPATCH fortran:
This bug comes about because check_assumed_size_reference did too much
for too long! In looking for the upper limit of the highest dimension
of an assumed size array, it looped through all the dimensions and all
the references. In consequence, it screwed up a reference line
arr(1)%p, where p is an array, pointer component. In fact, the
resolution of any assumed size reference needs only visit the last
dimension of the first gfc_ref. This patch does just that.
For what it's worth, I think that I was the author of this extravagence!
Bootstrapped and regtested on x86_ia64/FC8 - OK for trunk
(Note that this was tested on 4.3 because my trunk is heavy with
allocatable component patch:) )
Paul
2008-03-16 Paul Thomas <pault@gcc.gnu.org>
PR fortran/35470
* resolve.c (check_assumed_size_reference): Only visit the
first reference and look directly at the highest dimension.
2008-03-16 Paul Thomas <pault@gcc.gnu.org>
PR fortran/35470
* gfortran.dg/subref_array_pointer_3.f90 : New test.
--
The knack of flying is learning how to throw yourself at the ground and miss.
--Hitchhikers Guide to the Galaxy
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 133208)
--- gcc/fortran/resolve.c (working copy)
*************** static int need_full_assumed_size = 0;
*** 947,966 ****
static bool
check_assumed_size_reference (gfc_symbol *sym, gfc_expr *e)
{
- gfc_ref *ref;
- int dim;
- int last = 1;
-
if (need_full_assumed_size || !(sym->as && sym->as->type == AS_ASSUMED_SIZE))
return false;
! for (ref = e->ref; ref; ref = ref->next)
! if (ref->type == REF_ARRAY)
! for (dim = 0; dim < ref->u.ar.as->rank; dim++)
! last = (ref->u.ar.end[dim] == NULL)
! && (ref->u.ar.type == DIMEN_ELEMENT);
!
! if (last)
{
gfc_error ("The upper bound in the last dimension must "
"appear in the reference to the assumed size "
--- 947,958 ----
static bool
check_assumed_size_reference (gfc_symbol *sym, gfc_expr *e)
{
if (need_full_assumed_size || !(sym->as && sym->as->type == AS_ASSUMED_SIZE))
return false;
! if ((e->ref->u.ar.end[e->ref->u.ar.as->rank - 1] == NULL)
! && (e->ref->u.ar.as->type == AS_ASSUMED_SIZE)
! && (e->ref->u.ar.type == DIMEN_ELEMENT))
{
gfc_error ("The upper bound in the last dimension must "
"appear in the reference to the assumed size "
Index: gcc/testsuite/gfortran.dg/subref_array_pointer_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/subref_array_pointer_3.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/subref_array_pointer_3.f90 (revision 0)
***************
*** 0 ****
--- 1,15 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR35470, in which the pointer assignment would fail
+ ! because the assumed size 'arr' would get mixed up with the component
+ ! 'p' in the check for the upper bound of an assumed size array.
+ !
+ ! Contributed by Antony Lewis <antony@cosmologist.info>
+ !
+ subroutine sub(arr)
+ type real_pointer
+ real, pointer :: p(:)
+ end type real_pointer
+ type(real_pointer), dimension(*) :: arr
+ real, pointer :: p(:)
+ p => arr(1)%p
+ end subroutine