public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file.
@ 2020-05-18 22:54 longb at cray dot com
  2020-05-21 10:49 ` [Bug fortran/95195] " anlauf at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: longb at cray dot com @ 2020-05-18 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

* [Bug fortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
  2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
@ 2020-05-21 10:49 ` anlauf at gcc dot gnu.org
  2020-05-21 19:32 ` [Bug libfortran/95195] " anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-05-21 10:49 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org
   Last reconfirmed|                            |2020-05-21
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from anlauf at gcc dot gnu.org ---
Seems to be present in all versions.

Confirmed.

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

* [Bug libfortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
  2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
  2020-05-21 10:49 ` [Bug fortran/95195] " anlauf at gcc dot gnu.org
@ 2020-05-21 19:32 ` anlauf at gcc dot gnu.org
  2020-05-24 19:40 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-05-21 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |libfortran
           Priority|P3                          |P4

--- Comment #2 from anlauf at gcc dot gnu.org ---
The following patch generates a runtime error for namelist read:

diff --git a/libgfortran/io/list_read.c b/libgfortran/io/list_read.c
index 77d61421a0f..28744d21143 100644
--- a/libgfortran/io/list_read.c
+++ b/libgfortran/io/list_read.c
@@ -3549,6 +3549,14 @@ namelist_read (st_parameter_dt *dtp)
      name.  */
   namelist_info *prev_nl = NULL;

+  if (dtp->u.p.current_unit->flags.form == FORM_UNFORMATTED)
+    {
+      generate_error (&dtp->common, LIBERROR_OPTION_CONFLICT,
+                     "Namelist formatting not allowed for unit connected "
+                     "with FORM='UNFORMATTED'");
+      return;
+    }
+
   dtp->u.p.input_complete = 0;
   dtp->u.p.expanded_read = 0;

This generates:

At line 10 of file pr95195.f90 (unit = 10, file = 'test.dat')
Fortran runtime error: Namelist formatting not allowed for unit connected with
FORM='UNFORMATTED'

Error termination. Backtrace:
#0  0x7f80d510f1a7 in finalize_transfer
        at ../../../gcc-trunk/libgfortran/io/transfer.c:4128
#1  0x400b3b in test
        at /home/anlauf/gcc-bugs/pr95195.f90:10
#2  0x400b9c in main
        at /home/anlauf/gcc-bugs/pr95195.f90:12


Regtests cleanly for me.

Similar checks can be added for namelist write, list-directed formatting,
and non-advancing data transfers.  (F2018: 12.3.3.3)

Does this look better?

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

* [Bug libfortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
  2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
  2020-05-21 10:49 ` [Bug fortran/95195] " anlauf at gcc dot gnu.org
  2020-05-21 19:32 ` [Bug libfortran/95195] " anlauf at gcc dot gnu.org
@ 2020-05-24 19:40 ` anlauf at gcc dot gnu.org
  2020-05-26 19:34 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-05-24 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |anlauf at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from anlauf at gcc dot gnu.org ---
Slightly adjusted patch, posted for review:

https://gcc.gnu.org/pipermail/fortran/2020-May/054380.html

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

* [Bug libfortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
  2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
                   ` (2 preceding siblings ...)
  2020-05-24 19:40 ` anlauf at gcc dot gnu.org
@ 2020-05-26 19:34 ` cvs-commit at gcc dot gnu.org
  2020-05-26 19:37 ` anlauf at gcc dot gnu.org
  2020-06-08 19:01 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-26 19:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:8d8a25b0a7c3400c724e04e1d775d9f377216c04

commit r11-644-g8d8a25b0a7c3400c724e04e1d775d9f377216c04
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue May 26 21:21:19 2020 +0200

    PR libfortran/95195 - improve runtime error for namelist i/o to unformatted
file

    Namelist input/output to unformatted files is prohibited.
    Generate useful runtime errors instead instead of misleading ones.

    2020-05-26  Harald Anlauf  <anlauf@gmx.de>

    libgfortran/
            PR fortran/95195
            * io/transfer.c (finalize_transfer): Generate runtime error for
            namelist input/output to unformatted file.

    gcc/testsuite/
            PR fortran/95195
            * gfortran.dg/namelist_97.f90: New test.

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

* [Bug libfortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
  2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
                   ` (3 preceding siblings ...)
  2020-05-26 19:34 ` cvs-commit at gcc dot gnu.org
@ 2020-05-26 19:37 ` anlauf at gcc dot gnu.org
  2020-06-08 19:01 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-05-26 19:37 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from anlauf at gcc dot gnu.org ---
Fixed on master for gcc-11.

Thanks for the report!

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

* [Bug libfortran/95195] gfortran poorly handles a program error of writing a namelist to an unformatted file.
  2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
                   ` (4 preceding siblings ...)
  2020-05-26 19:37 ` anlauf at gcc dot gnu.org
@ 2020-06-08 19:01 ` cvs-commit at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-08 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:8cd239614e43c9dcc0838845aec504e5eb938dbd

commit r11-1068-g8cd239614e43c9dcc0838845aec504e5eb938dbd
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jun 8 21:00:11 2020 +0200

    PR fortran/95195 - Fortran testcase should clean up afterwards

    Change testcase to check error message (iomsg) at runtime, rather than to
crash.

    libgfortran/
            PR fortran/95091
            * io/transfer.c (finalize_transfer): Fix type in error message.

    gcc/testsuite/
            PR fortran/95195
            * gfortran.dg/namelist_97.f90: Adjust testcase.

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

end of thread, other threads:[~2020-06-08 19:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18 22:54 [Bug fortran/95195] New: gfortran poorly handles a program error of writing a namelist to an unformatted file longb at cray dot com
2020-05-21 10:49 ` [Bug fortran/95195] " anlauf at gcc dot gnu.org
2020-05-21 19:32 ` [Bug libfortran/95195] " anlauf at gcc dot gnu.org
2020-05-24 19:40 ` anlauf at gcc dot gnu.org
2020-05-26 19:34 ` cvs-commit at gcc dot gnu.org
2020-05-26 19:37 ` anlauf at gcc dot gnu.org
2020-06-08 19:01 ` cvs-commit 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).