From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F249385480A; Tue, 3 Nov 2020 07:18:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F249385480A From: "tkoenig at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block Date: Tue, 03 Nov 2020 07:18:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: enhancement X-Bugzilla-Who: tkoenig at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc bug_status resolution bug_severity dependson Message-ID: In-Reply-To: References: 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: Tue, 03 Nov 2020 07:18:30 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97320 Thomas Koenig changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tkoenig at gcc dot gnu.org Status|RESOLVED |NEW Resolution|DUPLICATE |--- Severity|normal |enhancement Depends on| |90302 --- Comment #6 from Thomas Koenig --- It's not an exact duplicate of PR 94978; that bug is about a false positive without -Wdo-subscript, whereas this one is about a false positive with -Wdo-subscript. The reason why this is rather difficult to resolve is one of translation phases. In the gfortran front end, we create a syntax tree from the Fortran source code. On the basis of that syntax tree (where we still know a lot about the langauge) we issue that warning. The next step is conversion to an intermediate language, which gets handed to the main part of gcc for further processing (known as the "middle end"). It is the middle which is does most of the optimizations, and which has the tools to do so. In this particular instance, we would need "range propagation" (where the compiler can infer the range of variables from previous statements). We don't do that in the front end, because a) it would be a major piece of work, and b) it would duplicate a lot of what the middle end already does. The most elegant solution would be support from the middle and back end to put in a pseudo statement, like a __bulitin_warning "function". Code like integer :: a(12) do i=3D1,10 a(i-1) =3D 1 could then be annotated like do i=3D1,10 if (0 < lbound(a)) call __builtin_warning ("index out of bounds") if (9 > ubound(a)) call __builtin_warning ("index out of bounds") a(i-1) =3D 1 and if the compiler could not prove that these statements get removed by dead code elimination, it would issue the warning in the final phase of translation. This would pretty much eliminate false positives, and would be far superior than what we currently do. Unfortunately, this is a part of a compiler with which I am almost totally unfamiliar, so I cannot help there. Some preliminary work has been done (see PR 90302), but I don't know how far it has progressed in the meantime. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D90302 [Bug 90302] Implement __builtin_warning=