public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/97320] New: False positive "Array reference out of bounds in loop" in a protecting if block
@ 2020-10-07 13:17 trnka at scm dot com
  2020-10-07 13:31 ` [Bug fortran/97320] " dominiq at lps dot ens.fr
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: trnka at scm dot com @ 2020-10-07 13:17 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-11-03  7:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 13:17 [Bug fortran/97320] New: False positive "Array reference out of bounds in loop" in a protecting if block trnka at scm dot com
2020-10-07 13:31 ` [Bug fortran/97320] " dominiq at lps dot ens.fr
2020-11-02 15:56 ` Jacques.Lebourlot at obspm dot fr
2020-11-02 17:03 ` kargl at gcc dot gnu.org
2020-11-02 17:09 ` Jacques.Lebourlot at obspm dot fr
2020-11-02 20:11 ` anlauf at gcc dot gnu.org
2020-11-03  7:18 ` tkoenig at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).