g77 bug with optimized nested loops, arrays, and -fno-automatic

Tim Freeman tim@fungible.com
Thu Feb 6 02:33:00 GMT 2003


Here's a shell interaction that illustrates a bug.  The bug is when
the program prints "Compiler bug" and stops.  :-).

If I leave out the -O2 or the -fno-automatic flag, the bug goes away.

If I leave out the otherwise pointless initialization of RMAX, the bug
goes away.

If I move the check for reg(2,2,2) above the loop that initializes
rmax, the bug goes away.

If I inline the call to param into main, the bug goes away.

The "IMPLICIT none"'s and the file names have nothing to do with the
bug.

The same problem happens with the g77 released with Red Hat 8.0.  I
haven't included the version number for that.  I also installed the
g77 from Debian unstable, got the same results, and spliced its
version information into the dialogue below.

> g77-3.2 --version  # This is Debian testing
GNU Fortran (GCC 3.2.1 20020924 (Debian prerelease)) 3.2.1 20020924 (prerelease)
>>>Chopped.<<<
> g77-3.2 --version # This is Debian unstable.
GNU Fortran (GCC 3.2.2 20030131 (Debian prerelease)) 3.2.2 20030131 (prerelease)
>>>Chopped.<<<
> g77-3.2 -O2 -W -fno-automatic mainFixed.f -o brennermd
> ./brennermd
 Compiler bug, reg(2,2,2)=  0.
> cat mainFixed.f
      IMPLICIT none
      call param
      END
      SUBROUTINE PARAM
      IMPLICIT none
      double precision RMAX(4,4),REG(4,4,4)
      integer i,j,k
      DO 12 I=1,2
           DO 11 J=1,2
                DO 10 K=1,2
                     REG(I,J,K)=1d0
10              CONTINUE
11         CONTINUE
12    CONTINUE 
      DO 61 I=1,4
           DO 60 J=1,4
                RMAX(I,J)=3d0
   60      CONTINUE
   61 CONTINUE
      if (reg(2,2,2) .ne. 1) then
         write (*,*) 'Compiler bug, reg(2,2,2)=', reg(2,2,2)
         stop
      end if
      RETURN
      END

>
-- 
Tim Freeman       
tim@fungible.com
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D  7180 76DF FE00 34B1 5C78 



More information about the Gcc-bugs mailing list