Bug 20163 - [4.0 only] gfortran - error opening direct access file
Summary: [4.0 only] gfortran - error opening direct access file
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: patch
: 20749 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-02-23 14:12 UTC by Dale Ranta
Modified: 2005-04-13 21:02 UTC (History)
2 users (show)

See Also:
Host: powerpc-apple-darwin7.8.0
Target:
Build:
Known to work: 4.1.0
Known to fail:
Last reconfirmed: 2005-03-22 23:05:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dale Ranta 2005-02-23 14:12:20 UTC
This is the essence of one the errors that one of my programs is seeing. It is a
Double Wammy - first the open of the direct access file fails for no reason -
then it get an internal library error. g77 and Absoft are happy with it.

[dir:~/tests/gfortran] dir% gfortran -g -o recursive recursive.f
[dir:~/tests/gfortran] dir% recursive
At line 14 of file recursive.f
Internal Error: Recursive library calls not allowed
[dir:~/tests/gfortran] dir% cat recursive.f
      program main
      CHARACTER*8 STATUS
      STATUS='SCRATCH'
      NT=55
      NTAP29=29
      NRECL=64
      NPUINT=4
        OPEN(UNIT=NT,STATUS=STATUS,ACCESS='DIRECT',
     $     FORM='UNFORMATTED',RECL=NRECL*NPUINT,ERR=999)
       STOP      
      
  999 CONTINUE
  
          OPEN (NTAP29, STATUS='SCRATCH')
  
      STOP
      END
Comment 1 Andrew Pinski 2005-02-23 14:19:57 UTC
Confirmed.
Comment 2 Thomas Koenig 2005-02-23 23:09:01 UTC
This is two bugs.

The first bug can be reduced to

$ cat open-opt.f
      open(unit=10,status="scratch ")
      end
$ gfortran open-opt.f
$ ./a.out
At line 1 of file open-opt.f
Fortran runtime error: Bad STATUS parameter in OPEN statement
Comment 3 Thomas Koenig 2005-02-23 23:29:43 UTC
This has a pretty good chance of fixing it.

Proper testing, Changelog entry, ... tomorrow.

Index: string.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libgfortran/runtime/string.c,v
retrieving revision 1.4
diff -c -r1.4 string.c
*** string.c    12 Jan 2005 21:27:31 -0000      1.4
--- string.c    23 Feb 2005 23:28:02 -0000
***************
*** 41,57 ****
  compare0 (const char *s1, int s1_len, const char *s2)
  {
    int i;

!   if (strncasecmp (s1, s2, s1_len) != 0)
!     return 0;
!
!   /* The rest of s1 needs to be blanks for equality.  */
!
!   for (i = strlen (s2); i < s1_len; i++)
!     if (s1[i] != ' ')
!       return 0;
!
!   return 1;
  }


--- 41,51 ----
  compare0 (const char *s1, int s1_len, const char *s2)
  {
    int i;
+   int len;

!   /* Strip traling blanks from the Fortran string.  */
!   len = fstrlen(s1, s1_len);
!   return strncasecmp(s1,s2,len) == 0;
  }


Comment 4 Thomas Koenig 2005-02-26 20:46:40 UTC
Patch for the first bug here:

http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01694.html
Comment 5 Thomas Koenig 2005-02-26 20:49:41 UTC
Here is a reduced test case for the second error:

$ cat open-after-error.f
      open(10,status="foo",err=100)
      call abort
 100  continue
      open(10,status="scratch")
      end
$ cat open-after-error.f
      open(10,status="foo",err=100)
      call abort
 100  continue
      open(10,status="scratch")
      end
$ gfortran open-after-error.f
$ ./a.out
At line 4 of file open-after-error.f
Internal Error: Recursive library calls not allowed
Comment 6 Dale Ranta 2005-02-27 14:05:26 UTC
Looks like a missing call to library_end ()in open.c. I added that one line and
the recursive error went away -

[dir:~/tests/gfortran] dir% gfortran -o recursive3 recursive3.f
[dir:~/tests/gfortran] dir% recursive3
[dir:~/tests/gfortran] dir% cat  recursive3.f
      open(10,status="foo",err=100)
      call abort
 100  continue
      open(10,status="scratch")
      end

> 
[dir:~] dir% diff -c /Users/dir/junk/io/open.c
/Users/dir/gfortran/gcc/libgfortran/io/open.c
*** /Users/dir/junk/io/open.c   Sat Jan 22 16:14:30 2005
--- /Users/dir/gfortran/gcc/libgfortran/io/open.c       Sat Feb 26 21:36:28 2005
***************
*** 480,488 ****
    if (flags.position == POSITION_UNSPECIFIED)
      flags.position = POSITION_ASIS;
  
!   if (ioparm.library_return != LIBRARY_OK)
      return;
! 
    u = find_unit (ioparm.unit);
  
    if (u == NULL)
--- 480,489 ----
    if (flags.position == POSITION_UNSPECIFIED)
      flags.position = POSITION_ASIS;
  
!   if (ioparm.library_return != LIBRARY_OK){
!     library_end ();
      return;
!   }
    u = find_unit (ioparm.unit);
  
    if (u == NULL)


(In reply to comment #5)
> Here is a reduced test case for the second error:
> 
> $ cat open-after-error.f
>       open(10,status="foo",err=100)
>       call abort
>  100  continue
>       open(10,status="scratch")
>       end
> $ cat open-after-error.f
>       open(10,status="foo",err=100)
>       call abort
>  100  continue
>       open(10,status="scratch")
>       end
> $ gfortran open-after-error.f
> $ ./a.out
> At line 4 of file open-after-error.f
> Internal Error: Recursive library calls not allowed
> 
Comment 7 GCC Commits 2005-03-29 08:37:54 UTC
Subject: Bug 20163

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	fxcoudert@gcc.gnu.org	2005-03-29 08:37:32

Modified files:
	gcc/testsuite  : ChangeLog 
	libgfortran    : ChangeLog 
	libgfortran/io : open.c 
Added files:
	gcc/testsuite/gfortran.dg: pr20163-2.f 

Log message:
	PR libfortran/20163
	* io/open.c (st_open): call library_end() before returning even if
	an error arises.
	
	* gfortran.dg/pr20163-2.f: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5228&r2=1.5229
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pr20163-2.f.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.178&r2=1.179
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/open.c.diff?cvsroot=gcc&r1=1.11&r2=1.12

Comment 9 Francois-Xavier Coudert 2005-03-29 08:42:45 UTC
Fixed.
Comment 10 GCC Commits 2005-04-09 19:37:20 UTC
Subject: Bug 20163

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tkoenig@gcc.gnu.org	2005-04-09 19:37:14

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/runtime: string.c 

Log message:
	2005-04-09  Thomas Koenig <Thomas.Koenig@online.de>
	
	PR libfortran/20163
	* runtime/string.c (compare0): Use fstrlen() to
	strip trailing blanks from option string.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.185&r2=1.186
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/runtime/string.c.diff?cvsroot=gcc&r1=1.4&r2=1.5

Comment 11 GCC Commits 2005-04-09 19:40:54 UTC
Subject: Bug 20163

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tkoenig@gcc.gnu.org	2005-04-09 19:40:48

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: open-options-blanks.f 

Log message:
	2005-04-09  Thomas Koenig  <Thomas.Koenig@online.de>
	
	PR libfortran/20163
	* gfortran.dg/open-options-blanks.f:  New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5313&r2=1.5314
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/open-options-blanks.f.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 12 Thomas Koenig 2005-04-10 09:41:04 UTC
First half is ixed in 4.1.0 - waiting for 4.0 to reopen.
Comment 13 Francois-Xavier Coudert 2005-04-12 08:50:55 UTC
*** Bug 20749 has been marked as a duplicate of this bug. ***
Comment 14 GCC Commits 2005-04-13 20:48:32 UTC
Subject: Bug 20163

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tkoenig@gcc.gnu.org	2005-04-13 20:48:16

Modified files:
	libgfortran    : ChangeLog 
	libgfortran/runtime: string.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: open-options-blanks.f 

Log message:
	Committed after approval on
	http://gcc.gnu.org/ml/gcc/2005-04/msg00613.html.
	
	2005-04-13  Thomas Koenig <Thomas.Koenig@online.de>
	
	PR libfortran/20163
	* runtime/string.c (compare0): Use fstrlen() to
	strip trailing blanks from option string.
	
	2005-04-13  Thomas Koenig  <Thomas.Koenig@online.de>
	
	PR libfortran/20163
	* gfortran.dg/open-options-blanks.f:  New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.163.2.17&r2=1.163.2.18
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/runtime/string.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4&r2=1.4.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.122&r2=1.5084.2.123
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/open-options-blanks.f.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 15 Thomas Koenig 2005-04-13 20:49:21 UTC
Fixed on 4.0 too.