Bug 87606 - Wrong array reference out of bounds warning
Summary: Wrong array reference out of bounds warning
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 8.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-13 19:40 UTC by AstroFloyd
Modified: 2018-10-14 09:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description AstroFloyd 2018-10-13 19:40:43 UTC
The following Fortran program (minimum working example) gives an erroneous array reference out of bounds warning:

program test
  implicit none
  integer :: i,iarr(10)
  do i=1,10
     if(i.gt.1) iarr(i-1) = i
  end do
end program test


$ gfortran -Wdo-subscript test.f90 -o test
test.f90:5:21:

   do i=1,10
           2          
      if(i.gt.1) iarr(i-1) = i
                     1
Warning: Array reference at (1) out of bounds (0 < 1) in loop beginning at (2) [-Wdo-subscript]
Comment 1 Thomas Koenig 2018-10-14 09:03:18 UTC
According to the docs:

-Wdo-subscript
Warn if an array subscript inside a DO loop could lead to an out-of-bounds access even if the compiler can not prove that the statement is actually executed, in cases like

  real a(3)
  do i=1,4
    if (condition(i)) then
      a(i) = 1.2
    end if
  end do
This option is implied by -Wextra.

Solution: Do not use the option unless you want it to do what it says.

Currently, we do not have error supressing pragmas, this would be an even better method.