Bug 23407

Summary: program works correctly with -g option but fails with -O2 option on LINUX
Product: gcc Reporter: Dale Ranta <dir>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs
Priority: P2    
Version: 4.1.0   
Target Milestone: ---   
Host: i686-pc-linux-gnu Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Dale Ranta 2005-08-15 21:11:18 UTC
This program works Ok on the Macintosh. On linux this program fails with -O2,
but works Ok with -g -


dir/tests> gfortran -O2 -o timefun02 timefun02.f
dir/tests> timefun02
 Error    1.00000000000000        1.00000000000000
STOP 0
dir/tests> gfortran -g -o timefun02 timefun02.f
dir/tests> timefun02
STOP 0
dir/tests> cat timefun02.f
      program main
      implicit real*8 (a-h,o-z)
      time2=0d0
      do 20 i=1,10
      time2 = time2 + 0.1d0
   20 continue
      call sub1(time2)
      stop
      end
      subroutine sub1(time)
      implicit real*8 (a-h,o-z)
      time2=0d0
      do 30 i=1,10
      time2 = time2 + 0.1d0
  30  continue
      if(time2.ne.time)then
         write(6,*)'Error ',time2,time
      endif
      return
      end

dir/tests> gfortran --v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --prefix=/home/dir/gfortran --enable-languages=c,f95
Thread model: posix
gcc version 4.1.0 20050815 (experimental)
Comment 1 Andrew Pinski 2005-08-15 21:23:48 UTC
This almost can be considered a bug in the processor (x86 that is).
The issue is that on x86 GCC is using excessive precision so you cannot really rely on equals with 
floating point.  Either use -ffloat-store or use -mfpmath=sse -msse2 or stop relying on float being 
equal.

This is a dup of bug 323.

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