There is a bad case of aliasing here:

$ cat pointer_function.f90
program Realloc
  IMPLICIT NONE
  REAL, DIMENSION(:), POINTER :: x
  INTEGER :: i
  x => NULL()
  x => myallocate(x)
contains
  FUNCTION myallocate(p)
    REAL, DIMENSION(:), POINTER :: p, myallocate
    INTEGER :: nold,ierr
    if (associated(p)) then
       print *,"p is associated"
    else
       print *,"p is not associated"
    end if
    allocate(myallocate(20))
    if (associated(p)) then
       print *,"p is associated"
    else
       print *,"p is not associated"
    end if
  END FUNCTION myallocate
end program Realloc
$ gfortran -fdump-tree-original pointer_function.f90
$ ./a.out
 p is not associated
 p is associated
$ tail -10 pointer_function.f90.t02.original
{
  struct array1_real4 x;
  static void myallocate (struct array1_real4 &, struct array1_real4 &);

  x.data = 0B;
  x.data = 0B;
  myallocate (&x, &x);
}

The two arguments to myallocate are bogus - they alias each other,
and they shouldn't.  A tempoaray array descriptor is needed here.

-- 
           Summary: Functions returning pointers with pointer argument
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23373

Reply via email to