Re: [PATCH, fortran] Fix Bug 124543 - INQUIRE: Sometimes returns incorrect values
Harald Anlauf <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.fortran |
|---|---|
| Message-ID | <[email protected]> |
Hi Jerry,
thanks for your efforts!
I played with the testcase, threw the NAG compiler on it, and
found a few minor nits:
1)
! Make sure there is no file with the name we will be using
open (lun, file=lfn, status='old', iostat=iostat)
if (iostat /= 0) then
close (lun, status='delete')
end if
Here the logic seems backwards to me: you want to delete an
existing file. It should rather read:
if (iostat == 0) then
...
2)
inquire (file=lfn, id=id, pending=pending, recl=recl) ! SEGV at
run-time w/gfortran
This crashes with NAG, because there is *no* pending asynchronous
transfer.
I recommend to replace that with
inquire (file=lfn, id=id, pending=pending, recl=recl,iostat=iostat)
and I also wonder if we should set iostat to non-zero (like NAG) and
test it with:
if (iostat == 0) stop 80
(This fails after your patch).
Similarly later on:
inquire (unit=lun, id=id, pending=pending, recl=recl,iostat=iostat)
if (iostat == 0) stop 123
The other differences I saw may be issues with NAG or an interpretation
issue.
So the patch is OK with the above addressed and suitably resolved.
Thanks,
Harald
On 3/29/26 04:38, Jerry D wrote:
> Hello All,
>
> The attached patch fixes numerous return values or missing checks.
>
> There were at least two places where we segfaulted on checking a
> gfc_unit value when the unit did not exist.
>
> I have not implemented inquire (unit=lun, leading_zero=leading_zero)
> since this is rather new and I prefer to add it after this patch. It is
> one of those examples of a new feature added that does not have a lot of
> value AFAICT. It will require some front-end work.
>
> The new test case is very busy. It is not too difficult to adjust if we
> miss anything there.
>
> Regression tested on X86_64.
>
> OK for mainline?
>
> Regards,
>
> Jerry
> -----
> fortran: Fix several issues with INQUIRE and unconnected units.
>
> PR libfortran/124543
>
> libgfortran/ChangeLog:
>
> * io/inquire.c (inquire_via_unit): Fix return value for
> NAMED. Add check for ACTION. Fix return values for
> ENCODING, PENDING, READ, WRITE, READWRITE.
> (inquire_via_filename): Add checks for ACTION, DELIM,
> ASYNCHRONOUS, and PENDING. Fix return value for
> ENCODING.
> * io/unix.c (inquire_access): Change return value from no
> to unknown.
>
> gcc/testsuite/ChangeLog:
>
> * gfortran.dg/pr124543.f90: New test.
>