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]
Other format: [Raw text]

[Bug fortran/84104] New: Minval gives incorrect results for certain compiler options


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84104

            Bug ID: 84104
           Summary: Minval gives incorrect results for certain compiler
                    options
           Product: gcc
           Version: 4.8.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yosef at astro dot rit.edu
  Target Milestone: ---

If st_z is a complex (2d) array with no element (1,1), under certain compiler
options, minval(abs(st_z - dcmplx(1,1)) returns 0, which is not correct.

This happens with the compiler options 
gfortran -O2  -ffast-math -fno-finite-math-only test.f90
Removing any one option from the command line removes the bug. Here's the test
code
program test
      implicit none
      integer, parameter :: nx = 5
      integer, parameter :: ny = 5
      integer, parameter :: wp = kind(1.0d0)

      complex(kind=wp), dimension(nx,ny):: st_z

      integer:: i,j

      do j=1, ny
        do i=1, nx
          st_z(i,j) = dcmplx(-i,-j)
        end do
      end do

      if (minval(abs(st_z - dcmplx(1,1))) < 1.0d-10) then
              write(*,*) "Bug triggered"
      endif
end program test

The bug is triggered for options
gfortran -OX  -ffast-math -fno-finite-math-only test.f90 

where X is 1, 2, 3, 4. But is not triggered if X is 0.
Also, removing "-fno-finite-math-only", or removing "-ffast-math"
suppresses the bug regardless of X.


Details of fortran version:

gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-linker-build-id --with-linker-hash-style=gnu
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin
--enable-initfini-array --disable-libgcj
--with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install
--with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64
--build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)

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