Bug 23407 - program works correctly with -g option but fails with -O2 option on LINUX
Summary: program works correctly with -g option but fails with -O2 option on LINUX
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.1.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-15 21:11 UTC by Dale Ranta
Modified: 2005-08-15 21:23 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
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 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 ***