This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

g77 optimization -O3 bug.


Dear Sirs,

I believe I found a "little" bug (it took me 2 weeks to localize it in a
huge programm) for the optimization -O3 option of the g77 compiler.
Maybe you will tell that it is not a bug (because without optimization,
or with the option -fno-automatic it work well), but I can tell you that
IT IS a bug. The code compiled with 4 others compilers (at maximum
optimization) worked well (included the old good f2c !!!). The code was
run on Linux (PPC version), I will send you the routine with problems,
in an attached file.

My best wishes,

Dr. Horatiu Palivan

Institut for Physical Chemistry
University of Basel
4056-BASEL
Switzerland
e-mail: palivanh@ubaclu.unibas.ch
*  Compiled with: g77 -O3 g77x.f -> bug
*                 g77 -O3 -fno-automatic g77x.f -> OK
*                 g77 g77x.f -> OK
*  Note: with option: -fno-automatic the code is OK (but this do not
*  means that it is not a bug at optimization: WITHOUT optimization
*  the code is OK, too !).
*-------------------------------------------------
      PARAMETER (IFAK=19)
C
*      COMMON /FAKUL/IP(IFAK),IPI(IFAK)
      dimension IP(19),IPI(19)
C
C     U. GOETZ   1967
C     H. Palivan 06/03/00
C      ln(p), p = prime number
C           First 19 prime numbers.
      IP(1)=2
      IP(2)=3
      IP(3)=5
      IP(4)=7
      IP(5)=11
      IP(6)=13
      IP(7)=17
      IP(8)=19
      IP(9)=23
      IP(10)=29
      IP(11)=31
      IP(12)=37
      IP(13)=41
      IP(14)=43
      IP(15)=47
      IP(16)=53
      IP(17)=59
      IP(18)=61
      IP(19)=67
C
C .......... blablabla
* here must be a Do cycle (only some values ...)
	k=4
      CALL PRIM(K,IFAK,IP,IPI)
	write(6,'(''*K='',i3,2x,19i3)')k,(ipi(i),i=1,19)
	k=6
      CALL PRIM(K,IFAK,IP,IPI)
	write(6,'(''*K='',i3,2x,19i3)')k,(ipi(i),i=1,19)
	k=8
      CALL PRIM(K,IFAK,IP,IPI)
	write(6,'(''*K='',i3,2x,19i3)')k,(ipi(i),i=1,19)
C .......... blablabla
      STOP
      END
* if the comments (*>>) are removed, and the two instructions are
* by the previously commented, the code is OK.
      SUBROUTINE PRIM(N,IFAK,IP,IPI)
C
C     Primzerlegung
C     IP(K) = K-te Primzahl
C     IPI(K) = Exponent von IP(K) in Zerlegung von N
C
C     U. GOETZ   1967
C     H. Palivan 06/03/00
C
*      DIMENSION IP(IFAK),IPI(IFAK) ! Identical for the 2
      DIMENSION IP(19),IPI(19)      ! declarations.
C
      NNK=N
      DO 3 I=1,IFAK
        NNI=NNK
        IPI(I)=0
*>>        ipx=ip(i)
    1 NNI=NNI/IP(I)      !(next one)
*>>    1   NNI=NNI/ipx
      IF((IP(I)*NNI) .ne. NNK) go to 3      !(next one)
*>>        IF((ipx*NNI) .ne. NNK) goto 3
          IPI(I)=IPI(I)+1
          NNK=NNI
          GOTO 1
    3 CONTINUE
*
      RETURN
      END
*-------------------------------------------------

* g77 version egcs-2.91.66 19990314 (egcs-1.1.2 release)
* (from FSF-g77 version 0.5.24-19981002)
** OUTPUT:
* compiled with "COMMON" instead of "dimension" in Main:
*K=  4    1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1
*K=  6    2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
*K=  8    1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1
* compiled with "dimension" instead of "COMMON" in Main:
*K=  4    1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
*K=  6    2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
*K=  8    1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
* CORRECT OUTPUT:
*K=  4    2  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
*K=  6    1  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
*K=  8    3  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]