aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2017-11-28 21:28:50 +0200
committerJanne Blomqvist <jb@gcc.gnu.org>2017-11-28 21:28:50 +0200
commit67c24a8bd6141021da49e005c0111bd42bfc7d08 (patch)
tree4255e7df80923463cf7ce62bf84f31f5f890ab13 /gcc
parent6df8934f6ad73b97181fc0a997b3eb8cd799b6a0 (diff)
downloadgcc-67c24a8bd6141021da49e005c0111bd42bfc7d08.zip
gcc-67c24a8bd6141021da49e005c0111bd42bfc7d08.tar.gz
gcc-67c24a8bd6141021da49e005c0111bd42bfc7d08.tar.bz2
PR 53796 Improve INQUIRE(RECL=...) handling
The current F2018 draft (N2137) specifies behavior of the RECL= specifier in the INQUIRE statement, where it previously was left as undefined. Namely: - If the unit is not connected, RECL= should be given the value -1. - If the unit is connected with stream access, RECL= should be given the value -2. Further, as PR 53796 describes, the handling of RECL= is poor in other ways as well. When the recl is set to the maximum possible (GFC_INTEGER_8_HUGE / LLONG_MAX), which it does by default except for preconnected units, and when INQUIRE(RECL=) is used with a 4 byte integer, the value is truncated and the 4 byte value is thus -1. Fixing this to generate an error is a lot of work, as currently the truncation is done by the frontend, the library sees only an 8 byte value with no indication that the frontend is going to copy it to a 4 byte one. Instead, this patch does a bit twiddling trick such that the truncated 4 byte value is GFC_INTEGER_4_HUGE while still being 0.99999999 * GFC_INTEGER_8_HUGE which is large enough for all practical purposes. Finally, the patch removes GFORTRAN_DEFAULT_RECL which was used only for preconnected units, and instead uses the same approach as describe above. Regtested on x86_64-pc-linux-gnu, Ok for trunk. gcc/fortran/ChangeLog: 2017-11-28 Janne Blomqvist <jb@gcc.gnu.org> PR fortran/53796 * gfortran.texi: Remove mentions of GFORTRAN_DEFAULT_RECL. libgfortran/ChangeLog: 2017-11-28 Janne Blomqvist <jb@gcc.gnu.org> PR fortran/53796 * io/inquire.c (inquire_via_unit): Set recl to -1 for unconnected units. * io/io.h (default_recl): New variable. * io/open.c (new_unit): Set recl to default_recl for sequential, -2 for stream access. * io/transfer.c (read_block_form): Test against default_recl instead of DEFAULT_RECL. (write_block): Likewise. * io/unit.c (init_units): Calculate max_offset, default_recl. * libgfortran.h (DEFAULT_RECL): Remove. * runtime/environ.c: Remove GFORTRAN_DEFAULT_RECL. gcc/testsuite/ChangeLog: 2017-11-28 Janne Blomqvist <jb@gcc.gnu.org> PR fortran/53796 * gfortran.dg/inquire_recl_f2018.f90: New test. From-SVN: r255215
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/gfortran.texi9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/inquire_recl_f2018.f9042
4 files changed, 52 insertions, 9 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 91c57e0..fc97158 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-28 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR fortran/53796
+ * gfortran.texi: Remove mentions of GFORTRAN_DEFAULT_RECL.
+
2017-11-28 Paul Thomas <pault@gcc.gnu.org>
PR fortran/83021
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 4b4688c..36c7b94 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -600,7 +600,6 @@ Malformed environment variables are silently ignored.
* GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
* GFORTRAN_SHOW_LOCUS:: Show location for runtime errors
* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
-* GFORTRAN_DEFAULT_RECL:: Default record length for new files
* GFORTRAN_LIST_SEPARATOR:: Separator for list output
* GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
@@ -683,14 +682,6 @@ where permitted by the Fortran standard. If the first letter
is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
in most cases. Default is not to print plus signs.
-@node GFORTRAN_DEFAULT_RECL
-@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new files
-
-This environment variable specifies the default record length, in
-bytes, for files which are opened without a @code{RECL} tag in the
-@code{OPEN} statement. This must be a positive integer. The
-default value is 1073741824 bytes (1 GB).
-
@node GFORTRAN_LIST_SEPARATOR
@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 67c1f27..e0e027b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-28 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR fortran/53796
+ * gfortran.dg/inquire_recl_f2018.f90: New test.
+
2017-11-28 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Martin Jambor <mjambor@suse.cz>
diff --git a/gcc/testsuite/gfortran.dg/inquire_recl_f2018.f90 b/gcc/testsuite/gfortran.dg/inquire_recl_f2018.f90
new file mode 100644
index 0000000..8a13340
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/inquire_recl_f2018.f90
@@ -0,0 +1,42 @@
+! { dg-do run }
+! PR 53796 INQUIRE(RECL=...)
+program inqrecl
+ implicit none
+ integer(8) :: r
+ integer :: r4
+ ! F2018 (N2137) 12.10.2.26: recl for unconnected should be -1
+ inquire(10, recl=r)
+ if (r /= -1) then
+ call abort()
+ end if
+
+ ! Formatted sequential
+ open(10, status="scratch")
+ inquire(10, recl=r)
+ inquire(10, recl=r4)
+ close(10)
+ if (r /= huge(0_8) - huge(0_4) - 1) then
+ call abort()
+ end if
+ if (r4 /= huge(0)) then
+ call abort()
+ end if
+
+ ! Formatted sequential with recl= specifier
+ open(10, status="scratch", recl=100)
+ inquire(10, recl=r)
+ close(10)
+ if (r /= 100) then
+ call abort()
+ end if
+
+ ! Formatted stream
+ ! F2018 (N2137) 12.10.2.26: If unit is connected
+ ! for stream access, recl should be assigned the value -2.
+ open(10, status="scratch", access="stream")
+ inquire(10, recl=r)
+ close(10)
+ if (r /= -2) then
+ call abort()
+ end if
+end program inqrecl