https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94978

--- Comment #1 from Fritz Reese <foreese at gcc dot gnu.org> ---
The regression is caused by r253156, which introduces the warning in the first
place. The relevant code is in frontend-passes.c (do_subscript). Apparently,
the FE is aware that when there is a conditional it cannot correctly simplify
the subscript bounds. However, in the testcase there is an inner DO-loop which,
when the bounds are reduced to the empty set, prevents the code from becoming
invalid. Therefore no warning should be issued.

The warning can be bypassed by guarding the inner DO-loop with any conditional,
including a vacuously true one:

$ diff -auw pascal.f03 pascal2.f03
--- pascal.f03  2020-05-06 19:14:50.966646632 -0400
+++ pascal2.f03 2020-05-06 19:23:48.209569659 -0400
@@ -9,9 +9,11 @@

 do i = 0, 8
   pascal(i,0) = 1
+  if (.true.) then
   do j = 1, i-1
     pascal(i,j) = pascal(i-1,j) + pascal(i-1,j-1)
   enddo
+  endif
   do j = i, 8
     pascal(i,j) = 0
   enddo
$ gfortran pascal2.f03


Normally the warning can be suppressed with -Wno-do-subscript, but the code in
do_subscript() determines that this is "definitely" an issue and therefore
moves the warning to category 0.

(An interesting note: moving the code in the testcase into a subroutine, rather
than the main program, suppresses the warning for GCC 8, but not GCC 9, 10, or
11.)

Reply via email to