public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98141] New: Segmentation fault with empty string sourced allocation
@ 2020-12-04 12:49 davidhneill at gmail dot com
  2020-12-04 16:25 ` [Bug fortran/98141] " davidhneill at gmail dot com
  2020-12-05 14:49 ` dominiq at lps dot ens.fr
  0 siblings, 2 replies; 3+ messages in thread
From: davidhneill at gmail dot com @ 2020-12-04 12:49 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/98141] Segmentation fault with empty string sourced allocation
  2020-12-04 12:49 [Bug fortran/98141] New: Segmentation fault with empty string sourced allocation davidhneill at gmail dot com
@ 2020-12-04 16:25 ` davidhneill at gmail dot com
  2020-12-05 14:49 ` dominiq at lps dot ens.fr
  1 sibling, 0 replies; 3+ messages in thread
From: davidhneill at gmail dot com @ 2020-12-04 16:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98141

--- Comment #1 from David Neill Asanza <davidhneill at gmail dot com> ---
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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug fortran/98141] Segmentation fault with empty string sourced allocation
  2020-12-04 12:49 [Bug fortran/98141] New: Segmentation fault with empty string sourced allocation davidhneill at gmail dot com
  2020-12-04 16:25 ` [Bug fortran/98141] " davidhneill at gmail dot com
@ 2020-12-05 14:49 ` dominiq at lps dot ens.fr
  1 sibling, 0 replies; 3+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-12-05 14:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98141

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-12-05

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed from at least GCC7 up to trunk (GCC11).

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-05 14:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-04 12:49 [Bug fortran/98141] New: Segmentation fault with empty string sourced allocation davidhneill at gmail dot com
2020-12-04 16:25 ` [Bug fortran/98141] " davidhneill at gmail dot com
2020-12-05 14:49 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).