public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/34795]  New: inquire statement , direct= specifier incorrectly returns YES
@ 2008-01-15 13:05 kendrick dot killian at colostate dot edu
  2008-01-15 20:04 ` [Bug fortran/34795] " burnus at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: kendrick dot killian at colostate dot edu @ 2008-01-15 13:05 UTC (permalink / raw)
  To: gcc-bugs

The inquire direct= specifier always returns YES regardless how the file is
created or actually opened.


The bug has been seen on gfortran versions
 gcc version 4.1.0 20060304 (Red Hat 4.1.0-3)   Target: x86_64-redhat-linux
 gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)  Target: i386-redhat-linux
 gcc version 4.1.2 20070925 (Red Hat 4.1.2-27)  Target: x86_64-redhat-linux
 gcc version 4.2.0 20060713 (experimental)      Target: powerpc-apple-darwin8

Causes code that depends on the returned value to read the file incorrectly and
generate an I/O error


Bug is reproducible with a simple program
==========================================================
      program testdirect
      character drct*4, acc*12
      logical opn

      open(unit=19,file='testdirect.f',status='OLD',err=170)
      inquire(unit=19, direct=drct, opened=opn, access=acc)
      write(*,*) "default open drct=",drct, "opened=",opn, "access=",acc
      close(19)

      open(unit=19,file='testdirect.f',status='OLD',err=170,
     &     access='SEQUENTIAL')
      inquire(unit=19, direct=drct, opened=opn, access=acc)
      write(*,*) "Sequent open drct=",drct, "opened=",opn, "access=",acc
      close(19)

      open(unit=19,file='testdirect.f',status='OLD',err=170,
     &     form='UNFORMATTED',access='DIRECT',recl=72)
      inquire(unit=19, direct=drct, opened=opn, access=acc)
      write(*,*) "direct  open drct=",drct, "opened=",opn, "access=",acc
      close(19)
      stop

170   write(*,*) "ERROR: unable to open testdirect.f"
      end
====================================================================

file name:     testdirect.f
compiled with: gfortran testdirect.f

File output:
 default open drct=YES opened= T access=SEQUENTIAL  
 Sequent open drct=YES opened= T access=SEQUENTIAL  
 direct  open drct=YES opened= T access=DIRECT      


correct output (produced by g77)
 default open drct=NO  opened= T access=SEQUENTIAL  
 Sequent open drct=NO  opened= T access=SEQUENTIAL  
 direct  open drct=YES opened= T access=DIRECT


-- 
           Summary: inquire statement , direct= specifier incorrectly
                    returns YES
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kendrick dot killian at colostate dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
@ 2008-01-15 20:04 ` burnus at gcc dot gnu dot org
  2008-01-16  2:34 ` kendrick dot killian at colostate dot edu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-01-15 20:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2008-01-15 19:12 -------
| correct output (produced by g77)
|  default open drct=NO  opened= T access=SEQUENTIAL  
|  Sequent open drct=NO  opened= T access=SEQUENTIAL  
|  direct  open drct=YES opened= T access=DIRECT

How do you know which answer is correct? I think this is the same problem as
formatted and unformatted: The answers are only correct with a certain
probability.

One can even open an UNFORMATTED file as FORMATTED though reading probably
produces only garbage.

As starting point I would recommend to read:
http://groups.google.com/group/comp.lang.fortran/msg/b2ab0a6e106d977c
(and maybe also the complete thread).

If you can then explain why a certain value is better than another, we might
change it. (By the way, the only true answer is "UNKNOWN".)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
  2008-01-15 20:04 ` [Bug fortran/34795] " burnus at gcc dot gnu dot org
@ 2008-01-16  2:34 ` kendrick dot killian at colostate dot edu
  2008-01-16  4:30 ` jvdelisle at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kendrick dot killian at colostate dot edu @ 2008-01-16  2:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kendrick dot killian at colostate dot edu  2008-01-16 00:50 -------
Subject: Re:  inquire statement , direct= specifier incorrectly returns YES

There is a three part definition of correct answer that mirrors
arguments in the formatted/unformatted thread. Noting that the
standard, 9.6.1.9, requires that DIRECT answer based on the
"set of allowed access methods".

Condition 1. (NOT the reported bug)
inquire on a file NOT connected/opened INQUIRE(NAME=existing_file,...)
Unless the file system maintains access methods or the runtime library
has a documented way of determining those method, the correct answer is
"UNKNOWN" as you stated. Assuming that nothing STOPS you from doing a
direct open, YES might be acceptable but it is NOT the most informative
answer as YES makes an affirmative statement about the file rather than
indicating a lack of restriction.


Condition 2 (The bug reported)
inquire on a CONNECTED file INQUIRE(UNIT=...)
Accessing a sequential unit with direct IO or sequential IO on a unit
opened for direct access should be undefined and generate read errors.
Errors should be sufficient to determine a unit's "allowed access  
methods".
Even if the implementation does not generate fatal errors, as possible
in the format/unformat discussion, then the data returned will be  
corrupt.
Inquire (UNIT= should provide information needed to read/write the unit
**AS OPENED** without corruption.


Lastly
Gfortran's response to the inquire direct= is INCONSISTENT with the
response provided my other compilers. I tested

Absoft   OS X FORTRAN 77/90/95 Compilers 7.0b, (c) 1987-2002, Absoft  
Corp
SUN      Sun WorkShop 6 update 1 Fortran 77/90/95 6.1 2000/09/11
COMPAQ   Compaq Visual Fortran Standard Edition 6.5.0  (c) 2000
g77      version 3.0.4 (Fortran Frontend version 0.5.26 20020220  
(release))

With all eight the above compilers, the test program returns:
   default open drct=NO  opened= T access=SEQUENTIAL
   Sequent open drct=NO  opened= T access=SEQUENTIAL
   direct  open drct=YES opened= T access=DIRECT

The common response, when consistent with the standard, is certainly the
preferred solution if not "correct" answer.




On Jan 15, 2008, at 12:12 PM, burnus at gcc dot gnu dot org wrote:

>
>
> ------- Comment #1 from burnus at gcc dot gnu dot org  2008-01-15  
> 19:12 -------
> | correct output (produced by g77)
> |  default open drct=NO  opened= T access=SEQUENTIAL
> |  Sequent open drct=NO  opened= T access=SEQUENTIAL
> |  direct  open drct=YES opened= T access=DIRECT
>
> How do you know which answer is correct? I think this is the same  
> problem as
> formatted and unformatted: The answers are only correct with a certain
> probability.
>
> One can even open an UNFORMATTED file as FORMATTED though reading  
> probably
> produces only garbage.
>
> As starting point I would recommend to read:
> http://groups.google.com/group/comp.lang.fortran/msg/b2ab0a6e106d977c
> (and maybe also the complete thread).
>
> If you can then explain why a certain value is better than another,  
> we might
> change it. (By the way, the only true answer is "UNKNOWN".)
>
>
> -- 
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
  2008-01-15 20:04 ` [Bug fortran/34795] " burnus at gcc dot gnu dot org
  2008-01-16  2:34 ` kendrick dot killian at colostate dot edu
@ 2008-01-16  4:30 ` jvdelisle at gcc dot gnu dot org
  2008-01-16  7:24 ` jvdelisle at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-01-16  4:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jvdelisle at gcc dot gnu dot org  2008-01-16 01:48 -------
I will investigate this further.  This has come up before in other previous
reports.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
                   ` (2 preceding siblings ...)
  2008-01-16  4:30 ` jvdelisle at gcc dot gnu dot org
@ 2008-01-16  7:24 ` jvdelisle at gcc dot gnu dot org
  2008-01-16  7:52 ` jvdelisle at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-01-16  7:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jvdelisle at gcc dot gnu dot org  2008-01-16 05:32 -------
I am not making a decision here yet.  I will keep this PR open until I fix
another minor issue I have found.

I would like to comment that to do what you want to do here without any
ambiguity your code should be using INQUIRE(unit=19, opened=opn, access=acc)
and test the two conditions to determine what to do:

 if (opn .and. acc="DIRECT
   ... do your direct stuff
 end if

This is truly the most portable way to do it.  I will also add that just taking
the F2003 standard at face value, gfortran has this right, IMHO.  The standard
does not assume that a unit is a particular kind of device or I/O unit.  There
are device types that just simply can not be access as DIRECT.

Respectfully, I think this is one of the most commonly misunderstood Fortran
features.  Its understandably frustrating.  I will return to this in a few
days.  I have two other bugs in front. (BTW, I already have a trivial patch
that will change gfortran behavior, complexity of the fix is not the issue)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
                   ` (3 preceding siblings ...)
  2008-01-16  7:24 ` jvdelisle at gcc dot gnu dot org
@ 2008-01-16  7:52 ` jvdelisle at gcc dot gnu dot org
  2008-01-19 16:32 ` jvdelisle at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-01-16  7:52 UTC (permalink / raw)
  To: gcc-bugs



-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jvdelisle at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-01-16 06:22:04
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
                   ` (4 preceding siblings ...)
  2008-01-16  7:52 ` jvdelisle at gcc dot gnu dot org
@ 2008-01-19 16:32 ` jvdelisle at gcc dot gnu dot org
  2008-01-20  8:02 ` jvdelisle at gcc dot gnu dot org
  2008-01-20  8:09 ` jvdelisle at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-01-19 16:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jvdelisle at gcc dot gnu dot org  2008-01-19 15:31 -------
Not that this reference is always right, but Metcalf, Reid, and Cohen state:

direct=dir where dir "... are character variables that are assigned the value
YES, NO, or UNKNOWN, depending on whether the file may be opened for ... direct
access ... or whether this can not be determined.

To me, key here is "may be opened" which implies the file is not open yet.  So,
if the file has been opened already,its nonsense to use inquire this way, but
the answer is obviously NO for a file opened for sequential.  The standard
could be improved by addressing this case where the file is already opened.
So based on that, I agree we change gfortran.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
                   ` (5 preceding siblings ...)
  2008-01-19 16:32 ` jvdelisle at gcc dot gnu dot org
@ 2008-01-20  8:02 ` jvdelisle at gcc dot gnu dot org
  2008-01-20  8:09 ` jvdelisle at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-01-20  8:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jvdelisle at gcc dot gnu dot org  2008-01-20 06:49 -------
Subject: Bug 34795

Author: jvdelisle
Date: Sun Jan 20 06:48:39 2008
New Revision: 131673

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131673
Log:
2008-01-20  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        PR libfortran/34795
        * gfortran.dg/inquire_13.f90: New test.

        PR libfortran/34659
        * gfortran.dg/continuation_9.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/continuation_9.f90
    trunk/gcc/testsuite/gfortran.dg/inquire_13.f90
Modified:
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

* [Bug fortran/34795] inquire statement , direct= specifier incorrectly returns YES
  2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
                   ` (6 preceding siblings ...)
  2008-01-20  8:02 ` jvdelisle at gcc dot gnu dot org
@ 2008-01-20  8:09 ` jvdelisle at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-01-20  8:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jvdelisle at gcc dot gnu dot org  2008-01-20 07:01 -------
Fixed:

Revision 131672 - (view) (download) - [select for diffs]
Modified Sun Jan 20 06:33:49 2008 UTC (26 minutes, 35 seconds ago) by jvdelisle
File length: 12184 byte(s)
Diff to previous 130805 (colored)

2008-01-19  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

        * io/inquire.c (inquire_via_unit): If a unit is opened, return values
        according to the open action for DIRECT, FORMATTED, and UNFORMATTED.
        (inquire_via_filename): Return "UNKNOWN" for SEQUENTIAL, DIRECT,
        FORAMATTED, and UNFORMATTED inquiries.
        * io/unix.c (inquire_sequential): Return "UNKNOWN" when appropriate
        for files that are not opened. (inquire_direct): Same.
        (inquire_formatted): Same.


-- 

jvdelisle at gcc dot gnu dot org changed:

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


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34795


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

end of thread, other threads:[~2008-01-20  7:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-15 13:05 [Bug fortran/34795] New: inquire statement , direct= specifier incorrectly returns YES kendrick dot killian at colostate dot edu
2008-01-15 20:04 ` [Bug fortran/34795] " burnus at gcc dot gnu dot org
2008-01-16  2:34 ` kendrick dot killian at colostate dot edu
2008-01-16  4:30 ` jvdelisle at gcc dot gnu dot org
2008-01-16  7:24 ` jvdelisle at gcc dot gnu dot org
2008-01-16  7:52 ` jvdelisle at gcc dot gnu dot org
2008-01-19 16:32 ` jvdelisle at gcc dot gnu dot org
2008-01-20  8:02 ` jvdelisle at gcc dot gnu dot org
2008-01-20  8:09 ` jvdelisle at gcc dot gnu dot 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).