[Bug fortran/98141] New: Segmentation fault with empty string sourced allocation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98141 Bug ID: 98141 Summary: Segmentation fault with empty string sourced allocation Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: davidhneill at gmail dot com Target Milestone: --- The following example produces a segmentation fault on a sourced allocation from the empty string to an unlimited polymorphic allocatable. This also happens when the source is a 0-length character array instead of the empty string literal. The segfault is present in all versions I've tried: 7.5.0, 8.4.0, 9.3.0, 10.2.0 $ cat empty_string_segfault.f90 module foo type, public :: any_scalar class(*), allocatable :: value contains procedure :: alloc end type contains subroutine alloc (this, value) class(any_scalar), intent(out) :: this class(*), intent(in) :: value allocate(this%value, source=value) end subroutine alloc end module foo program prog use foo type(any_scalar) :: s1, s2, s3 character(len=0) :: c call s1%alloc(' ') !! No problem call s2%alloc('') !! Segfault call s3%alloc(c) !! Segfault end program $ gfortran -Wall -Wextra -g empty_string_segfault.f90 $ ./a.out Program received signal SIGSEGV: Segmentation fault - invalid memory reference. My system is Ubuntu 20.04 on Intel hardware with all gfortran versions installed directly from the Ubuntu repositories.
[Bug fortran/98141] Segmentation fault with empty string sourced allocation
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98141 --- Comment #1 from David Neill Asanza --- Here are even shorter examples: $ cat short01.f90 program short01 class(*), allocatable :: a, b, c character(len=0) :: s allocate(a, source=s) !! No problem allocate(character(len=0)::b) allocate(c, source=b) !! Segfault end program $ cat short02.f90 program short02 class(*), allocatable :: a, b allocate(a, source='') !! No problem allocate(b, source=a) !! Segfault end program So it seems the underlying issue is the sourced allocation from a 0-length unlimited polymorphic type.
[Bug fortran/98573] New: Dynamic type lost on assignment
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573 Bug ID: 98573 Summary: Dynamic type lost on assignment Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: davidhneill at gmail dot com Target Milestone: --- Created attachment 49904 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49904&action=edit Minimal reproducer In the following example, the dynamic type of an unlimited polymorphic array is lost on an assignment but conserved (as expected) on a sourced allocation. This happens in all versions I've tried: 7.5.0, 8.4.0, 9.3.0, 10.2.0 My system is Ubuntu 20.04 on Intel hardware with all gfortran versions installed directly from the Ubuntu repositories. $ cat type_lost.f90 module foo type, public:: box class(*), allocatable :: val(:) end type contains subroutine store1(this, val) class(box), intent(out) :: this class(*), intent(in) :: val(:) this%val = val end subroutine store1 subroutine store2(this, val) class(box), intent(out) :: this class(*), intent(in) :: val(:) allocate(this%val, source=val) end subroutine store2 subroutine vector_type(val) class(*), intent(in) :: val(:) select type (val) type is (integer) print '("INTEGER")' class default print '("OTHER")' end select end subroutine vector_type end module foo program prog use foo type(box) :: b call store1(b, [1, 2, 3]) call vector_type(b%val) ! OTHER call store2(b, [1, 2, 3]) call vector_type(b%val) ! INTEGER end program $ gfortran -g -Wall -Wextra minimal.f90 $ ./a.out OTHER INTEGER
[Bug fortran/98573] Dynamic type lost on assignment
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573 --- Comment #1 from David Neill Asanza --- Removing the derived type container triggers a segfault. $ cat segfault.f90 module foo contains subroutine store1(arr, val) class(*), allocatable, intent(out) :: arr(:) class(*), intent(in) :: val(:) arr = val end subroutine store1 subroutine store2(arr, val) class(*), allocatable, intent(out) :: arr(:) class(*), intent(in) :: val(:) allocate(arr, source=val) end subroutine store2 end module foo program prog use foo class(*), allocatable :: arr(:) call store1(arr, [1, 2, 3]) ! SEGFAULT call store2(arr, [1, 2, 3]) ! NO PROBLEM end program $ gfortran -g -Wall -Wextra minimal.f90 $ ./a.out Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
[Bug fortran/98573] Dynamic type lost on assignment
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573 --- Comment #2 from David Neill Asanza --- Created attachment 49905 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49905&action=edit Minimal reproducer for segmentation fault.
[Bug fortran/98573] Dynamic type lost on assignment
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573 --- Comment #3 from David Neill Asanza --- A related case when the array is 0-length. In this case, the dynamic type is lost in both assignment and sourced allocation. $ cat type_lost_0_length.f90 module foo type, public:: box class(*), allocatable :: val(:) end type contains subroutine store1(this, val) class(box), intent(out) :: this class(*), intent(in) :: val(:) this%val = val end subroutine store1 subroutine store2(this, val) class(box), intent(out) :: this class(*), intent(in) :: val(:) allocate(this%val, source=val) end subroutine store2 subroutine vector_type(val) class(*), intent(in) :: val(:) select type (val) type is (integer) print '("INTEGER")' class default print '("OTHER")' end select end subroutine vector_type end module foo program prog use foo type(box) :: b integer, allocatable :: arr1(:) integer, dimension(0) :: arr2 allocate(arr1(0)) call store1(b, arr1) call vector_type(b%val) ! OTHER call store2(b, arr1) call vector_type(b%val) ! OTHER call store1(b, arr2) call vector_type(b%val) ! OTHER call store2(b, arr2) call vector_type(b%val) ! OTHER end program $ gfortran -g -Wall -Wextra type_lost_0_length.f90 $ ./a.out OTHER OTHER OTHER OTHER
[Bug fortran/98573] Dynamic type lost on assignment
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573 --- Comment #4 from David Neill Asanza --- Created attachment 49906 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49906&action=edit Reproducer for 0-length case.
[Bug fortran/98573] Dynamic type lost on assignment
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573 --- Comment #6 from David Neill Asanza --- Thanks for looking into this Paul. I'm looking forward to having this fixed. :)