[Bug libfortran/40652] New: fortran io unit number specified in a short integer causes open to fail.

yaknai at yahoo dot com gcc-bugzilla@gcc.gnu.org
Sat Jul 4 18:43:00 GMT 2009


This problem appeared when code was recompiled after upgrading from
gcc/gfortran 4.2.4 to 4.3, and was isolated using gcc 4.4.0  on a GNU/Linux
Fedora 11 system (32bit intel).  


$ gcc -v
 Using built-in specs.
Target: i586-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch=i586
--build=i586-redhat-linux
Thread model: posix
gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) 



Example fortran program which demonstrates the problem: 

  implicit none
      integer*4 kmpi
      integer*2 shortkmpi
      integer ios
      character test_file*10

      kmpi=12
      shortkmpi=kmpi

      test_file='test.dat'
c     open and write a test file on unit 12
      open(kmpi, file=test_file, status='replace')
      write(kmpi, *) 1
      write(kmpi, *) 2
      write(kmpi, *) 3
      close(kmpi)

      write(6,*) 'Try to open and read using integer for unit'
      open(kmpi, file=test_file, status='old', iostat=ios) 
      if (ios .eq. 0) then
        write(6,*) '    Successful open using integer unit. '
        close(kmpi)
      else
       write(6,*) '    Error, failed to open file using integer unit'
      endif


      write(6,*)
      write(6,*) 'Try to open and read using integer*2 for unit'
      open(shortkmpi, file=test_file, status='old', iostat=ios)
      if(ios .eq. 0) then
        write(6,*) '    Successful open using integer*2 unit.'
        close(shortkmpi)
      else
        write(6,*) '    Error, failed to open file using integer*2 unit'
      endif

      write(6,*)
      write(6,*) 'Watch what happens to close() with integer*2 for unit'
      open(kmpi, file=test_file, status='old', iostat=ios)
      close(shortkmpi)

      stop
      end


$ gfortran -Wall -o opentest opentest.f
$ opentest
 Try to open and read using integer for unit
     Successful open using integer unit. 

 Try to open and read using integer*2 for unit
     Error, failed to open file using integer*2 unit

 Watch what happens to close() with integer*2 for unit
At line 41 of file opentest.f (unit = 8302168)
Fortran runtime error: Unit number in I/O statement too large

I then compiled gcc-4.2.4 
$ gcc-42 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2.4/configure --program-suffix=-42
--enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.2.4

$ gfortran-42 -Wall -o opentest-42 opentest.f
$ opentest-42
 Try to open and read using integer for unit
     Successful open using integer unit. 

 Try to open and read using integer*2 for unit
     Successful open using integer*2 unit.

 Watch what happens to close() with integer*2 for unit

Note that no unit number error occurs here.

----------------------------------------------

The message 

         At line 41 of file opentest.f (unit = 8302168)
         Fortran runtime error: Unit number in I/O statement too large

might suggest that unit numbers stored in integer*2 are being accessed in the
fortran io library call as integer*4 ??

I did not find anything in the known bug list or release notes related to this.


-- 
           Summary:  fortran io unit number specified in a short integer
                    causes open to fail.
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: yaknai at yahoo dot com


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



More information about the Gcc-bugs mailing list