public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
@ 2020-05-06 23:22 foreese at gcc dot gnu.org
  2020-05-06 23:26 ` [Bug fortran/94978] " foreese at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: foreese at gcc dot gnu.org @ 2020-05-06 23:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94978
           Summary: [8/9/10/11 Regression] Bogus warning "Array reference
                    at (1) out of bounds in loop beginning at (2)"
           Product: gcc
           Version: 8.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: foreese at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48472
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48472&action=edit
Testcase which exhibits the regression

The following issues a bogus warning which cannot be disabled except with -w.
The warning is not present in 7.x or earlier. Tried with 8.4.1, 9.3.1, 10 and
11.x (current trunk). Attached is a simple test case, which builds Pascal's
triangle of order 8 and exhibits the regression.

$ gfortran pascal.f03
pascal.f03:13:25:

   10 | do i = 0, 8
      |           2              
......
   13 |     pascal(i,j) = pascal(i-1,j) + pascal(i-1,j-1)
      |                         1
Warning: Array reference at (1) out of bounds (-1 < 0) in loop beginning at (2)
pascal.f03:13:41:

   10 | do i = 0, 8
      |           2                              
......
   13 |     pascal(i,j) = pascal(i-1,j) + pascal(i-1,j-1)
      |                                         1
Warning: Array reference at (1) out of bounds (-1 < 0) in loop beginning at (2)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
@ 2020-05-06 23:26 ` foreese at gcc dot gnu.org
  2020-05-07  7:28 ` rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: foreese at gcc dot gnu.org @ 2020-05-06 23:26 UTC (permalink / raw)
  To: gcc-bugs

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.)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
  2020-05-06 23:26 ` [Bug fortran/94978] " foreese at gcc dot gnu.org
@ 2020-05-07  7:28 ` rguenth at gcc dot gnu.org
  2020-05-18  8:56 ` tkoenig at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-07  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |8.5
           Keywords|                            |diagnostic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
  2020-05-06 23:26 ` [Bug fortran/94978] " foreese at gcc dot gnu.org
  2020-05-07  7:28 ` 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
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-05-18  8:56 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Blocks|                            |90302
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-05-18
                 CC|                            |tkoenig at gcc dot gnu.org

--- Comment #2 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Two ways to fix this: When checking for outer do loops, also check
if the inner one will be executed at all.

Or PR 90302, which is looking more attractive than ever.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90302
[Bug 90302] Implement __builtin_warning

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-07-26  7:58 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |tkoenig at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Let's see what can be done about this.(In reply to Thomas Koenig from comment
#2)
> Two ways to fix this: When checking for outer do loops, also check
> if the inner one will be executed at all.
> 
> Or PR 90302, which is looking more attractive than ever.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2020-11-02 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |trnka at scm dot com

--- Comment #4 from anlauf at gcc dot gnu.org ---
*** Bug 97320 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-14  8:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2021-04-16 16:22 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|tkoenig at gcc dot gnu.org         |unassigned at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [9/10/11/12 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-04-16 16:22 ` tkoenig at gcc dot gnu.org
@ 2021-05-14  9:53 ` jakub at gcc dot gnu.org
  2021-06-01  8:17 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|8.5                         |9.4

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 8 branch is being closed.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [9/10/11/12 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.4                         |9.5

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [10/11/12/13 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2021-06-01  8:17 ` rguenth at gcc dot gnu.org
@ 2022-05-27  9:42 ` 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
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [10/11/12/13 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  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
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:40 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/94978] [11/12/13/14 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)"
  2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2022-06-28 10:40 ` jakub at gcc dot gnu.org
@ 2023-07-07 10:37 ` rguenth at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-07 10:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06 23:22 [Bug fortran/94978] New: [8/9/10/11 Regression] Bogus warning "Array reference at (1) out of bounds in loop beginning at (2)" foreese at gcc dot gnu.org
2020-05-06 23:26 ` [Bug fortran/94978] " foreese at gcc dot gnu.org
2020-05-07  7:28 ` 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

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).