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.

Reply via email to