gcc/libgfortran/io
Janne Blomqvist 67c24a8bd6 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
2017-11-28 21:28:50 +02:00
..
close.c close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
fbuf.c close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
fbuf.h close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
file_pos.c re PR fortran/80741 ([Regression 7/8] DTIO wrong code causes incorrect behaviour of namelist READ) 2017-05-17 20:33:20 +00:00
format.c re PR libfortran/81938 (valgrind error message and heap-buffer-overflow on address sanitized libgfortran.so) 2017-10-27 17:50:22 +00:00
format.h Update copyright years. 2017-01-01 13:07:43 +01:00
inquire.c PR 53796 Improve INQUIRE(RECL=...) handling 2017-11-28 21:28:50 +02:00
intrinsics.c close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
io.h PR 53796 Improve INQUIRE(RECL=...) handling 2017-11-28 21:28:50 +02:00
list_read.c re PR fortran/78387 (OpenMP segfault/stack size exceeded writing to internal file) 2017-08-28 03:42:47 +00:00
lock.c close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
open.c PR 53796 Improve INQUIRE(RECL=...) handling 2017-11-28 21:28:50 +02:00
read.c close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
size_from_kind.c Update copyright years. 2017-01-01 13:07:43 +01:00
transfer.c PR 53796 Improve INQUIRE(RECL=...) handling 2017-11-28 21:28:50 +02:00
transfer128.c Update copyright years. 2017-01-01 13:07:43 +01:00
unit.c PR 53796 Improve INQUIRE(RECL=...) handling 2017-11-28 21:28:50 +02:00
unix.c unix.c (buf_write): Return early if there is nothing to write. 2017-07-24 10:42:23 +00:00
unix.h close.c: Fix white space in pointer declarations and comment formats where applicable. 2017-04-11 14:51:25 +00:00
write.c PR 83097 Use __BYTE_ORDER__ predefined macro instead of runtime check 2017-11-22 21:19:13 +02:00
write_float.def Update copyright years. 2017-01-01 13:07:43 +01:00