This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/25607] New: wrong code at -O2 -ffast-math on opteron ?
- From: "jv244 at cam dot ac dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Dec 2005 21:34:02 -0000
- Subject: [Bug target/25607] New: wrong code at -O2 -ffast-math on opteron ?
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
on this system
> uname -a
Linux pcihopt1 2.6.4-52-smp #1 SMP Wed Apr 7 01:58:54 UTC 2004 x86_64 x86_64
x86_64 GNU/Linux
with the latest 4.0 (branch) of gfortran (but also with the 4.0.1 release):
GNU Fortran 95 (GCC 4.0.3 20051230 (prerelease))
I'm getting the following error with valgrind for this valid program:
> cat test.f90
IMPLICIT NONE
integer, parameter :: ndf=6
real(KIND=8), allocatable, dimension(:) :: eigval,work
ALLOCATE(eigval(ndf))
ALLOCATE(work(ndf))
eigval=1.0_8
CALL set_hes_eig(ndf,eigval,work)
END
SUBROUTINE set_hes_eig(ndf,eigval,work)
IMPLICIT NONE
INTEGER, INTENT(IN) :: ndf
REAL(KIND=8), INTENT(INOUT) :: eigval(ndf), work(ndf)
REAL(KIND=8), PARAMETER :: one = 1.0_8
INTEGER :: indf
LOGICAL :: neg
DO indf = 1, ndf
IF( eigval(indf) < 0.0_8 )THEN
work(indf) = - one
ELSE
work(indf) = one
END IF
END DO
END SUBROUTINE set_hes_eig
> gcc_40_branch/build/bin/gfortran -g -O2 -ffast-math test.f90
> valgrind --tool=memcheck ./a.out
==30181== Memcheck, a memory error detector.
==30181== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==30181== Using LibVEX rev 1367, a library for dynamic binary translation.
==30181== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==30181== Using valgrind-3.0.1, a dynamic binary instrumentation framework.
==30181== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==30181== For more details, rerun with: -v
==30181==
==30181== Invalid read of size 8
==30181== at 0x400862: set_hes_eig_ (test.f90:18)
==30181== by 0x4007FD: MAIN__ (test.f90:7)
==30181== by 0x40089D: main (fmain.c:18)
==30181== Address 0x12329498 is 0 bytes after a block of size 72 alloc'd
==30181== at 0x11B1C166: malloc (vg_replace_malloc.c:149)
==30181== by 0x11C2B0B8: _gfortrani_get_mem (memory.c:99)
==30181== by 0x11C2B0EC: malloc_with_header (memory.c:125)
==30181== by 0x11C2B220: allocate_size (memory.c:228)
==30181== by 0x40075E: MAIN__ (test.f90:4)
==30181== by 0x40089D: main (fmain.c:18)
The error goes away using '-O2' or '-O1 -ffast-math'
On an intel chip I get this error as well using '-march=pentium4 -mfpmath=sse
-O2 -ffast-math'
I haven't seen any wrong results in the output of this code, but I guess this
is worth looking into anyway, as this won't be fortran specific.
--
Summary: wrong code at -O2 -ffast-math on opteron ?
Product: gcc
Version: 4.0.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jv244 at cam dot ac dot uk
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25607