https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64578
Bug ID: 64578
Summary: Seg-fault and ICE with unlimited polymorphic array
pointer function
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: damian at sourceryinstitute dot org
The code below seg faults with a gfortran 5.0 build dated 20141222 and
generates an internal compiler error when the print statement is uncommented.
The same code compiles, executes without error, and the print statement prints
"T" with the Cray compiler. Similar code also compiles and executes cleanly
with the Intel and NAG compilers, although I didn't test this exact (reduced)
case with Intel and NAG.
Damian
$cat unlim-poly-array-ptr-func.f90
type foo
real, allocatable :: component(:)
end type
type (foo), target :: f
class(*), pointer :: ptr(:)
allocate(f%component(1),source=[0.])
call associate_pointer(f,ptr)
ptr => return_pointer(f) ! runtime segmentation fault
!print *,associated(return_pointer(f)) ! ICE
contains
subroutine associate_pointer(this, item)
class(foo), target :: this
class(*), pointer :: item(:)
item => this%component
end subroutine
function return_pointer(this)
class(foo), target :: this
class(*), pointer :: return_pointer(:)
return_pointer => this%component
end function
end
$gfortran unlim-poly-array-ptr-func.f90
$./a.out
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:
#0 0x7FA26BE8EBB7
#1 0x7FA26BE8DDB0
#2 0x7FA26B39949F
#3 0x400F55 in return_pointer.3443 at unlim-poly-array-ptr-func.f90:0
#4 0x400A46 in MAIN__ at unlim-poly-array-ptr-func.f90:0
Segmentation fault (core dumped)
$gfortran --version | head -1
GNU Fortran (GCC) 5.0.0 20141222 (experimental)