From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 223B83857819; Wed, 7 Oct 2020 13:17:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 223B83857819 From: "trnka at scm dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/97320] New: False positive "Array reference out of bounds in loop" in a protecting if block Date: Wed, 07 Oct 2020 13:17:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: trnka at scm dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Oct 2020 13:17:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97320 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 =3D 1, 10 | 2=20=20=20=20=20=20=20 ...... 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. Inspect= ing the .optimized output confirms this. I can reproduce this using GCC 8 through 10 (GNU Fortran (GCC) 10.2.1 20200= 827 (Red Hat 10.2.1-3)), with or without -O2. =3D=3D=3D=3D=3D do-subscript-test.f90 =3D=3D=3D=3D=3D subroutine do_subscript_test() implicit none integer :: i real :: a(10) i_: do i =3D 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=