[Bug fortran/84506] INQUIRE(pos=) always sets pos=0 with -fdefault-integer-8
sgk at troutmask dot apl.washington.edu
gcc-bugzilla@gcc.gnu.org
Thu Feb 22 00:26:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84506
--- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Thu, Feb 22, 2018 at 12:08:24AM +0000, sgk at troutmask dot
apl.washington.edu wrote:
> program TestInquire
> implicit none
> integer(8) :: iUnit
> integer(8) :: iPos
> open(newunit=iunit, file='output.txt', access='stream', status='replace')
> write(iUnit) 'TEXT'
> inquire(iUnit, pos=iPos)
> print *, iPos
> end program TestInquire
>
It related to the automatic allocate of UNIT numbers with NEWUNIT.
If I do
iunit = 10
open(unit=iunit, file='output.txt', access='stream', status='replace')
One gets the right answer.
Looking in io/inquire.c, one has
void
st_inquire (st_parameter_inquire *iqp)
{
gfc_unit *u;
library_start (&iqp->common);
if ((iqp->common.flags & IOPARM_INQUIRE_HAS_FILE) == 0)
{
u = find_unit (iqp->common.unit);
inquire_via_unit (iqp, u);
}
(gdb) p iqp->common
$1 = {flags = 8192, unit = 10, filename = 0x4a6180 "d.f90", line = 9,
iomsg_len = 4806240, iomsg = 0x2008d0010 "", iostat = 0xc}
(gdb) p u
$2 = (gfc_unit *) 0x200ce6f00
Now with newunit.
(gdb) p iqp->common
$1 = {flags = 8192, unit = -3, filename = 0x4a6140 "d.f90", line = 9,
iomsg_len = 4806192, iomsg = 0x2008d0010 "", iostat = 0xc}
(gdb) p u
$2 = (gfc_unit *) 0x0
Whoops. u = 0x0, then runs into line 228-229.
if ((cf & IOPARM_INQUIRE_HAS_STRM_POS_OUT) != 0)
*iqp->strm_pos_out = (u != NULL) ? u->strm_pos : 0;
and there's your 0.
More information about the Gcc-bugs
mailing list