The following testcase is extracted from gfortran.dg/pr19928-2.f90. It shows
that the array index is evaluated multiple times.

$ cat u.f90
  type t
    integer, dimension (5) :: field
  end type t
  type (t), dimension (2) :: a
  integer :: calls

  a(1)%field = 0
  a(2)%field = 0
  calls = 0
  if (sum(a(foo(calls))%field) /= 0) call abort
  if (calls .ne. 1) print *, "bar", calls

contains
  function foo (calls)
    integer :: calls, foo
    calls = calls + 1
    foo = 2
  end function foo 
end
$ gfortran u.f90 && ./a.out
$ gfortran u.f90 -fbounds-check && ./a.out
 bar           3


-- 
           Summary: Multiple evaluation of array index with bounds checking
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: fxcoudert at gcc dot gnu dot org
        ReportedBy: fxcoudert at gcc dot gnu dot org
OtherBugsDependingO 27766
             nThis:


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32036

Reply via email to