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/71795] New: Two Bugs in array constructors (optimization)


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

            Bug ID: 71795
           Summary: Two Bugs in array constructors (optimization)
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: c.friedrich@fz-juelich.de
  Target Milestone: ---

1st bug: 

There is a problem with array constructors and optimization in gfortran 4.9.1
in the following code:

----------

     program test

     implicit none
     integer :: i,n

# ifdef BUG
     integer, allocatable :: a(:)
     allocate ( a(1) )
# else
     integer :: a(1)
# endif

     n = 1
     a = 2

     write(*,*) (any(a(i).eq.(/1,2,3/)) ,i=1,n)
     write(*,*) (/ (any(a(i).eq.(/1,2,3/)) ,i=1,n) /)
     write(*,*) any ( (/ (any(a(i).eq.(/1,2,3/)) ,i=1,n) /) )

     end

-----------

The result should obviously read
T T T.
However, I also get the incorrect result
T F F:

gfortran -O0 -cpp test.f   -->  correct
gfortran -O1 -cpp test.f   -->  correct
gfortran -O2 -cpp test.f   -->  correct
gfortran -O3 -cpp test.f   -->  correct
gfortran -O0 -cpp -DBUG test.f   -->  correct
gfortran -O1 -cpp -DBUG test.f   -->  incorrect
gfortran -O2 -cpp -DBUG test.f   -->  incorrect
gfortran -O3 -cpp -DBUG test.f   -->  incorrect


2nd bug:

A similar problem appears in

----------

      program test

      implicit none
      integer :: i,j,n

      real(8) :: arr(1,1,3)
      real(8) :: d(3)

      arr = 1d0
      n   = 1
      d   = (/ ( sum ( (/ (arr(j,j,i), j=1,1) /) ) , i=1,3 ) /) / n  !!!

      write(*,*) d

      end

----------

It runs correctly without optimization, but with optimization (all levels) it
gives
Infinity Infinity Infinity

Without "/ n" at "!!!" it runs correctly with optimizations, too.


Thank you!

Christoph

---

BTW, this is the output of "gcc -v":

Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --disable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-51)

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