[Bug fortran/97320] New: False positive "Array reference out of bounds in loop" in a protecting if block
trnka at scm dot com
gcc-bugzilla@gcc.gnu.org
Wed Oct 7 13:17:14 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320
Bug ID: 97320
Summary: False positive "Array reference out of bounds in loop"
in a protecting if block
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: trnka at scm dot com
Target Milestone: ---
Compiling the following testcase with "gfortran -c -Wdo-subscript
do-subscript-test.f90" leads to a bunch of warnings like the following:
do-subscript-test.f90:13:26:
7 | i_: do i = 1, 10
| 2
......
13 | a(i-4) > a(i-5)) &
| 1
Warning: Array reference at (1) out of bounds (-4 < 1) in loop beginning at (2)
[-Wdo-subscript]
Given that all these accesses are in an "if (i > 5)" block, the warnings are
false positives and the out-of-bounds accesses cannot really occur. Inspecting
the .optimized output confirms this.
I can reproduce this using GCC 8 through 10 (GNU Fortran (GCC) 10.2.1 20200827
(Red Hat 10.2.1-3)), with or without -O2.
===== do-subscript-test.f90 =====
subroutine do_subscript_test()
implicit none
integer :: i
real :: a(10)
i_: do i = 1, 10
if (i > 5) then
if (a(i) > a(i-1) .and. &
a(i-1) > a(i-2) .and. &
a(i-2) > a(i-3) .and. &
a(i-3) > a(i-4) .and. &
a(i-4) > a(i-5)) &
exit i_
end if
end do i_
end subroutine
More information about the Gcc-bugs
mailing list