Bug 40652 (PR40638) - fortran io unit number specified in a short integer causes open to fail.
Summary: fortran io unit number specified in a short integer causes open to fail.
Status: RESOLVED DUPLICATE of bug 40638
Alias: PR40638
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-04 18:43 UTC by Ian Kay
Modified: 2009-07-04 20:35 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Kay 2009-07-04 18:43:26 UTC
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.
Comment 1 Jerry DeLisle 2009-07-04 19:47:44 UTC
see PR40638 which was recently reported and fixed yesterday. There is a patch in the PR

*** This bug has been marked as a duplicate of 40638 ***