public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "foreese at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
Date: Wed, 06 May 2020 23:26:40 +0000	[thread overview]
Message-ID: <bug-94978-4-jYv4oLHBwn@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94978-4@http.gcc.gnu.org/bugzilla/>

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	other threads:[~2020-05-06 23:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 23:22 [Bug fortran/94978] New: " foreese at gcc dot gnu.org
2020-05-06 23:26 ` foreese at gcc dot gnu.org [this message]
2020-05-07  7:28 ` [Bug fortran/94978] " rguenth at gcc dot gnu.org
2020-05-18  8:56 ` tkoenig at gcc dot gnu.org
2020-07-26  7:58 ` tkoenig at gcc dot gnu.org
2020-11-02 20:11 ` anlauf at gcc dot gnu.org
2021-01-14  8:42 ` rguenth at gcc dot gnu.org
2021-04-16 16:22 ` tkoenig at gcc dot gnu.org
2021-05-14  9:53 ` [Bug fortran/94978] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:17 ` rguenth at gcc dot gnu.org
2022-05-27  9:42 ` [Bug fortran/94978] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:40 ` jakub at gcc dot gnu.org
2023-07-07 10:37 ` [Bug fortran/94978] [11/12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94978-4-jYv4oLHBwn@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).