public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/96122] New: Segfault when using finalizer
@ 2020-07-08 18:24 abensonca at gcc dot gnu.org
  2020-07-08 20:09 ` [Bug fortran/96122] " dominiq at lps dot ens.fr
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: abensonca at gcc dot gnu.org @ 2020-07-08 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96122
           Summary: Segfault when using finalizer
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abensonca at gcc dot gnu.org
  Target Milestone: ---

The following code segfaults with gfortran 11.0.0:


module a
  type vs
     character(len=1), dimension(:), allocatable :: ch
   contains
     final :: vsf
  end type vs
  type mtd
     type(vs), dimension(2) :: n
  end type mtd
contains
  subroutine c()
    type(mtd) :: m
    allocate(m%n(1)%ch(1))
    m%n(1)%ch(1)="a"
    allocate(m%n(2)%ch(1))
    m%n(2)%ch(1)="b"
    return
  end subroutine c
  subroutine vsf(s)
    type(vs), intent(inout) :: s
    if (allocated(s%ch)) deallocate(s%ch)
    return
  end subroutine vsf
end module a
program b
  use a
  call c()
end program b



$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-git/configure --prefix=/home/abenson/Galacticus/Tools
--enable-languages=c,c++,fortran --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20200705 (experimental) (GCC) 

$ gfortran tmp.F90 -g

$ ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7f47668d61ef in ???
        at
/data001/abenson/Galacticus/Tools/glibc-2.12.1/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
#1  0x40118f in __a_MOD___final_a_Vs
        at /home/abenson/Galacticus/Nightlies/galacticus/tmp.F90:30
#2  0x400bfa in __a_MOD___final_a_Mtd
        at /home/abenson/Galacticus/Nightlies/galacticus/tmp.F90:30
#3  0x401556 in __a_MOD_c
        at /home/abenson/Galacticus/Nightlies/galacticus/tmp.F90:22
#4  0x401562 in b
        at /home/abenson/Galacticus/Nightlies/galacticus/tmp.F90:34
#5  0x401599 in main
        at /home/abenson/Galacticus/Nightlies/galacticus/tmp.F90:33
Segmentation fault


The problem doesn't occur if the finalizer for type "vs" isn't used. It also
doesn't occur if the "n" component of type "mtd" has dimension(1) or is a
scalar.

The finalizer in this case is pointless (since it just deallocates an
allocatable, which would happen automatically if no finalizer were used), but
as far as I can see is legal code.

This appears to be a regression (worked in 10.1) but I haven't yet tracked down
exactly where the problem was introduced.

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

end of thread, other threads:[~2023-03-18 17:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 18:24 [Bug fortran/96122] New: Segfault when using finalizer abensonca at gcc dot gnu.org
2020-07-08 20:09 ` [Bug fortran/96122] " dominiq at lps dot ens.fr
2020-07-08 20:12 ` abensonca at gcc dot gnu.org
2020-07-11 17:36 ` tkoenig at gcc dot gnu.org
2022-01-17 10:56 ` pault at gcc dot gnu.org
2022-02-01 12:20 ` pault at gcc dot gnu.org
2023-03-18  7:56 ` cvs-commit at gcc dot gnu.org
2023-03-18 17:28 ` pault at gcc dot gnu.org

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).