Again on gfortran for Mac OS-X

FX Coudert fxcoudert@gmail.com
Sat Jan 5 21:47:00 GMT 2008


Hi Paolo,

Ante-scriptum: Unless advised to do so, please do not send me private  
mails about gfortran: posting to the mailing-list allows other to  
help, especially if I don't have an answer (this is the case here) or  
am not available, plus it helps keeping track of the problem for  
future reference (and is available on the web archives).


> Dear FX (Francois?)

Both work fine.

> let me disturb you again with gfortran. I managed to extract a small
> piece of code that demonstrates (on my machine, with gfortran version
> 20071231) the problem I was mentioning in my previous message:
>
>> [...] derived types as local variables: they lose their value from  
>> one
>> call to another, even if they have the "save" attribute
>
> Actually, "allocatable arrays of derived types":

I can confirm that your program below also crashed on x86_64-linux  
with gfortran-4.3.0-20071206. I have no access to any other compiler  
at the moment, but your code seem (at first glance) legal; someone  
else here will probably have a more definite opinion on that matter.  
 From the output of -fdump-tree-original, it looks like the compiler  
deallocates your allocated derived type on exit of the mah  
subroutine; if this code is indeed legal, then fixing the bug might  
simply be a matter of not performing this automatic deallocation for  
saved variables.

Thanks for the report,
FX



> program boh
>   !
>   call mah (0)
>   call mah (1)
>   call mah (2)
>   !
> end program boh
> !
> subroutine mah (i)
>   !
>   integer, intent(in) :: i
>   !
>   type mix_type
>      real(8), allocatable :: a(:)
>      complex(8), allocatable :: b(:)
>   end type mix_type
>   type(mix_type), allocatable, save :: t(:)
>   integer :: j, n=1024
>   !
>   if (i==0) then
>      allocate (t(1))
>      allocate (t(1)%a(n))
>      allocate (t(1)%b(n))
>      do j=1,n
>         t(1)%a(j) = j
>         t(1)%b(j) = n-j
>      end do
>   end if
>   c = sum( t(1)%a(:) ) + sum( t(1)%b(:) )
>   print *, 'c=',c
>   if ( i==2) then
>      deallocate (t(1)%b)
>      deallocate (t(1)%a)
>      deallocate (t)
>   end if
> end subroutine mah
>
> Maybe you will find this piece of code a perversion, but it looks
> correct to me (I am not a big f90 expert). At the second call of
> subroutine mah, it coredumps. It works if the array t(1) is
> replaced by a single variable t. It works with g95. I haven't
> access right now to any other machine with recent versions
> of gfortran so I cannot say whether it is OS-X specific or not.
> Best regards
>
> Paolo
> ---
> Paolo Giannozzi, Dept of Physics, University of Udine
> via delle Scienze 208, 33100 Udine, Italy
> Phone +39-0432-558216, fax +39-0432-558222



More information about the Fortran mailing list