------- Comment #1 from janus at gcc dot gnu dot org 2010-07-29 19:36 ------- Here is a reduced/modified version of the code in comment #0, which also exhibits a runtime segfault, although the code seems to be valid:
module polynomial implicit none private type, public :: polynom complex, allocatable, dimension(:) :: a integer :: n contains procedure :: init_from_coeff procedure :: get_degree procedure :: add_poly end type polynom contains subroutine init_from_coeff(self, coeff) class(polynom), intent(inout) :: self complex, dimension(:), intent(in) :: coeff self%n = size(coeff) - 1 allocate(self%a(self%n + 1)) self%a = coeff print *,"ifc:",self%a end subroutine init_from_coeff function get_degree(self) result(n) class(polynom), intent(in) :: self integer :: n print *,"gd" n = self%n end function get_degree subroutine add_poly(self) class(polynom), intent(in) :: self integer :: s print *,"ap" s = self%get_degree() !!!! fails here end subroutine end module polynomial program test_poly use polynomial type(polynom) :: p1 call p1%init_from_coeff([(1,0),(2,0),(3,0)]) call p1%add_poly() end program test_poly After being compiled with gfortran r162688 on x86_64-unknown-linux-gnu, it prints the following output: ifc: ( 1.0000000 , 0.0000000 ) ( 2.0000000 , 0.0000000 ) ( 3.0000000 , 0.0000000 ) ap Segmentation fault Valgrind says: ==25251== Invalid read of size 8 ==25251== at 0x400A02: __polynomial_MOD_init_from_coeff (c0.f90:42) ==25251== by 0x400950: __polynomial_MOD_add_poly (c0.f90:36) ==25251== by 0x400DCF: MAIN__ (c0.f90:47) ==25251== by 0x400E30: main (c0.f90:42) ==25251== Address 0x1c is not stack'd, malloc'd or (recently) free'd ==25251== ==25251== ==25251== Process terminating with default action of signal 11 (SIGSEGV) ==25251== Access not within mapped region at address 0x1C ==25251== at 0x400A02: __polynomial_MOD_init_from_coeff (c0.f90:42) ==25251== by 0x400950: __polynomial_MOD_add_poly (c0.f90:36) ==25251== by 0x400DCF: MAIN__ (c0.f90:47) ==25251== by 0x400E30: main (c0.f90:42) This is a very strange error. It seems "init_from_coeff" is called from "add_poly", although this is definitely not the case in the Fortran code. Maybe something goes wrong in the vtab, like PPCs having wrong addresses, etc. -- janus at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|0000-00-00 00:00:00 |2010-07-29 19:36:06 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44912