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

            Bug ID: 59561
           Summary: [4.9 Regression] warning: iteration 4 invokes
                    undefined behavior
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janus at gcc dot gnu.org

Found when working on PR 55207 ...


With the following modification:

Index: gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90    (revision
206100)
+++ gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90    (working copy)
@@ -3,7 +3,8 @@

       integer, parameter :: nx = 3, ny = 4

-      integer :: i, j, too_big
+      integer :: i, j
+      integer, save :: too_big

       integer, parameter, dimension(nx,ny) :: p = &
         reshape((/ (i*i, i=1,size(p)) /), shape(p))


so that this test case becomes:


! { dg-do run }
! { dg-options "-fbounds-check" }

      integer, parameter :: nx = 3, ny = 4

      integer :: i, j
      integer, save :: too_big

      integer, parameter, dimension(nx,ny) :: p = &
        reshape((/ (i*i, i=1,size(p)) /), shape(p))

      integer, dimension(nx,ny) :: a

      integer, dimension(:), allocatable :: b

      allocate(b(nx))

      a = p
      too_big = ny + 1

      b = sum(a(:,1:too_big),2)
      end
! { dg-shouldfail "outside of expected range" }


trunk gives:

$ gfortran-4.9 inline_sum_bounds_check_1.f90 -O2
inline_sum_bounds_check_1.f90: In function ‘MAIN__’:
inline_sum_bounds_check_1.f90:21:0: warning: iteration 4 invokes undefined
behavior [-Waggressive-loop-optimizations]
       b = sum(a(:,1:too_big),2)
 ^
inline_sum_bounds_check_1.f90:21:0: note: containing loop
inline_sum_bounds_check_1.f90: In function ‘main’:
inline_sum_bounds_check_1.f90:21:0: warning: iteration 4 invokes undefined
behavior [-Waggressive-loop-optimizations]
       b = sum(a(:,1:too_big),2)
 ^
inline_sum_bounds_check_1.f90:21:0: note: containing loop


with -O2 and -O3, while 4.8 did not do that. Probably the warning is ok, since
the test case is supposed to trigger a runtime error ("Index '5' of dimension 2
of array 'a' outside of expected range (4:1)").

However, I see three possible problems:
1) The question is why it only happens with SAVE.
2) I don't understand why the warning has 'iteration 4'. Shouldn't iteration 5
be the problem?
3) The warning appears twice.

Reply via email to