------- Additional Comments From pault at gcc dot gnu dot org 2005-08-13 09:31
-------
(In reply to comment #0)
Edmund,
>
> professional. Is there a workaround or is this a bug which must be fixed?
>
>
Thomas beat you to it!
In the mean time, the following works:
program Realloc
USE nrtype; USE nrutil
IMPLICIT NONE
REAL(SP), DIMENSION(:), POINTER :: x, y
INTEGER(I4B) :: i
allocate(x(10))
forall(i=1:ubound(x,1)) x(i)=i
write(*,"(10F6.2)") x
y => reallocate(x,20) ! Use y...
x => y ! ...and then point x to y
forall(i=1:ubound(x,1)) x(i)=2*i
write(*,"(20F6.2)") x
end program Realloc
For some reason, the compiler is not detecting the dependency and putting the
result of reallocate in a temporary. What happens is that reallocate does all
the right things, up until the deallocate..... which it does to the lhs, being
the same as the result, ie to x! An alternative fix is to comment out the
deallocate.
I'll take a look see over the next few days. It's a bit of code that I need to
revisit for another reason.
Best regards
Paul T
> 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.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23373