[Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320 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=1,10 a(i-1) = 1 could then be annotated like do i=1,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) = 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=90302 [Bug 90302] Implement __builtin_warning
[Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320 anlauf at gcc dot gnu.org changed: What|Removed |Added Resolution|--- |DUPLICATE Status|WAITING |RESOLVED --- Comment #5 from anlauf at gcc dot gnu.org --- See PR 94978. *** This bug has been marked as a duplicate of bug 94978 ***
[Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320 --- Comment #4 from Jacques Le Bourlot --- (In reply to kargl from comment #3) > (In reply to Jacques Le Bourlot from comment #2) > > > > The compiler should see that "IF (i >= 1)" THEN "i-1 >= 0". Quoting the > > manual is not an adequate answer. An upgrade would be most welcomed. > > > > gfortran is mostly maintained by a diminishing number of contributors. > Messages telling the few remaining contributors what they ought to > do are likely to fall on deaf ears. Patches from new contributors > are welcomed; otherwise, sometime in the future, perhaps a decade > or so, someone might care enough to try to fix this annoyance. In the > meantime, add -Wno-do-subscript to your options. My apologies. I did not mean to be rude or to complain. And I am not skilled enough to contribute. Sorry. But I will keep -Wdo-subscript, because I need the few cases that are *real* positives. Jacques
[Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320 kargl at gcc dot gnu.org changed: What|Removed |Added CC||kargl at gcc dot gnu.org --- Comment #3 from kargl at gcc dot gnu.org --- (In reply to Jacques Le Bourlot from comment #2) > > The compiler should see that "IF (i >= 1)" THEN "i-1 >= 0". Quoting the > manual is not an adequate answer. An upgrade would be most welcomed. > gfortran is mostly maintained by a diminishing number of contributors. Messages telling the few remaining contributors what they ought to do are likely to fall on deaf ears. Patches from new contributors are welcomed; otherwise, sometime in the future, perhaps a decade or so, someone might care enough to try to fix this annoyance. In the meantime, add -Wno-do-subscript to your options.
[Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320 Jacques Le Bourlot changed: What|Removed |Added CC||Jacques.Lebourlot at obspm dot fr --- Comment #2 from Jacques Le Bourlot --- Same here. This is annoying because *some* warnings ARE relevant, and I need them to clean a huge (and old) code. But they are lost in too many false positives. Here is the test case I can provide (similar to Tomas') - PROGRAM Warn_Bug INTEGER, PARAMETER :: N = 2 INTEGER, DIMENSION(0:N) :: a INTEGER :: i a = [ (i, i = 0, N) ] DO i = 0, N IF (i == 0) THEN PRINT *, " Do nothing" ELSE IF (i >= 1) THEN PRINT *, " OK:", a(i) - a(i-1) ENDIF ENDDO END PROGRAM Warn_Bug - The compiler should see that "IF (i >= 1)" THEN "i-1 >= 0". Quoting the manual is not an adequate answer. An upgrade would be most welcomed. Thank you. Jacques
[Bug fortran/97320] False positive "Array reference out of bounds in loop" in a protecting if block
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97320 Dominique d'Humieres changed: What|Removed |Added Ever confirmed|0 |1 Status|UNCONFIRMED |WAITING Last reconfirmed||2020-10-07 --- Comment #1 from Dominique d'Humieres --- The manual says Warn if an array subscript inside a DO loop could lead to an out-of-bounds access even if the compiler cannot prove that the statement is actually executed, in cases like or don't use -Wdo-subscript if there is an IF in the DO block.