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

            Bug ID: 95195
           Summary: gfortran poorly handles a program error of writing a
                    namelist to an unformatted file.
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: longb at cray dot com
  Target Milestone: ---

gfortran poorly handles a program error of writing a namelist to an unformatted
file.

> cat test.f90
      program test
              character(len=16) my_form
              character(len=240) msg
              data my_form /'unformatted'/
              namelist /nml1/ i, j, k
              i = 1; j = 2; k = 3
              open (unit=10, file='test.dat')
              write (10, nml=nml1)
              close (10)
              open (unit=10, file='test.dat', form=my_form)
                    read (unit=10, nml=nml1)
              close (unit=10, status='delete')
      end program test


> gfortran test.f90
> ./a.out

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

Backtrace for this error:
#0 0x7fadb087459f in ???
#1 0x7fadb15bf69e in fbuf_getc
at ../../../cray-gcc-9.3.0-202003310324.b29d417121fbe/libgfortran/io/fbuf.h:78
#2 0x7fadb15bf69e in next_char_default
at
../../../cray-gcc-9.3.0-202003310324.b29d417121fbe/libgfortran/io/list_read.c:215
#3 0x7fadb15bf69e in next_char_default
at
../../../cray-gcc-9.3.0-202003310324.b29d417121fbe/libgfortran/io/list_read.c:207
#4 0x7fadb15c8db7 in finalize_transfer
at
../../../cray-gcc-9.3.0-202003310324.b29d417121fbe/libgfortran/io/transfer.c:4109
#5 0x400bf7 in ???
#6 0x400c7c in ???
#7 0x7fadb085f349 in ???
#8 0x400779 in ???
at ../sysdeps/x86_64/start.S:120
#9 0xffffffffffffffff in ???
Segmentation fault (core dumped)

> gfortran --version
GNU Fortran (GCC) 9.3.0 20200312 (Cray Inc.)
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



A diagnostic message along the lines of the Cray or Intel compilers is
preferred:

> module swap PrgEnv-gnu PrgEnv-cray
> ftn test.f90
> ./a.out

lib-4080 : UNRECOVERABLE library error
A formatted read or write is not allowed on an unformatted file.

Encountered during a namelist READ from unit 10
Fortran unit 10 is connected to a sequential unformatted file: "test.dat"
Aborted (core dumped)



> module swap PrgEnv-cray PrgEnv-intel
> ifort test.f90
> ./a.out
forrtl: severe (257): formatted I/O to unit open for unformatted transfers,
unit 10, file /<path removed>/test.dat
Image PC Routine Line Source
a.out 000000000040546B Unknown Unknown Unknown
a.out 000000000041EF5E Unknown Unknown Unknown
a.out 0000000000402C31 Unknown Unknown Unknown
a.out 0000000000402A12 Unknown Unknown Unknown
libc-2.26.so 00007FC2FABAF34A __libc_start_main Unknown Unknown
a.out 000000000040292A Unknown Unknown Unknown

Reply via email to