[Bug fortran/38802] New: Seg fault for RESULT with allocatable components

pault at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sun Jan 11 12:15:00 GMT 2009


Posted on the list by Marco Restelli http://gcc.gnu.org/ml/fortran/2009-01/

$ gfortran test.f90 -o test
$ ./test
Segmentation fault

$ gfortran --version
GNU Fortran (GCC) 4.4.0 20090110 (experimental) [trunk revision 143243]

System:
Linux 2.6.23-gentoo-r6 x86_64 AMD Turion(tm) 64 Mobile Technology
ML-32 AuthenticAMD GNU/Linux


module mod_a
 implicit none
 public :: a_fun, t_1, t_2
 private

 type t_1
  real :: coeff
 end type t_1

 type t_2
  type(t_1), allocatable :: mons(:)
 end type t_2

contains

 function a_fun(r) result(p)
 integer, intent(in) :: r

 type(t_2) :: p(r+1)
 ! Using an allocatable works
 !type(t_2), allocatable :: p(:)
 ! allocate(p(r+1))

 write(*,*) 'shape(p) is ', shape(p)

 end function a_fun

end module mod_a

A workaround is to not use the RESULT variable.  The code shows that the result
is being nullified before its upper bound is established.

Paul  
program test
 use mod_a, only: a_fun, t_1, t_2
 implicit none
 type(t_2) x(1)

 x = a_fun(0)
end program test


-- 
           Summary: Seg fault for RESULT with allocatable components
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pault at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list