public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior
@ 2013-12-19 13:38 janus at gcc dot gnu.org
  2013-12-19 15:21 ` [Bug fortran/59561] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-12-19 13:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

            Bug ID: 59561
           Summary: [4.9 Regression] warning: iteration 4 invokes
                    undefined behavior
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janus at gcc dot gnu.org

Found when working on PR 55207 ...


With the following modification:

Index: gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90    (revision
206100)
+++ gcc/testsuite/gfortran.dg/inline_sum_bounds_check_1.f90    (working copy)
@@ -3,7 +3,8 @@

       integer, parameter :: nx = 3, ny = 4

-      integer :: i, j, too_big
+      integer :: i, j
+      integer, save :: too_big

       integer, parameter, dimension(nx,ny) :: p = &
         reshape((/ (i*i, i=1,size(p)) /), shape(p))


so that this test case becomes:


! { dg-do run }
! { dg-options "-fbounds-check" }

      integer, parameter :: nx = 3, ny = 4

      integer :: i, j
      integer, save :: too_big

      integer, parameter, dimension(nx,ny) :: p = &
        reshape((/ (i*i, i=1,size(p)) /), shape(p))

      integer, dimension(nx,ny) :: a

      integer, dimension(:), allocatable :: b

      allocate(b(nx))

      a = p
      too_big = ny + 1

      b = sum(a(:,1:too_big),2)
      end
! { dg-shouldfail "outside of expected range" }


trunk gives:

$ gfortran-4.9 inline_sum_bounds_check_1.f90 -O2
inline_sum_bounds_check_1.f90: In function ‘MAIN__’:
inline_sum_bounds_check_1.f90:21:0: warning: iteration 4 invokes undefined
behavior [-Waggressive-loop-optimizations]
       b = sum(a(:,1:too_big),2)
 ^
inline_sum_bounds_check_1.f90:21:0: note: containing loop
inline_sum_bounds_check_1.f90: In function ‘main’:
inline_sum_bounds_check_1.f90:21:0: warning: iteration 4 invokes undefined
behavior [-Waggressive-loop-optimizations]
       b = sum(a(:,1:too_big),2)
 ^
inline_sum_bounds_check_1.f90:21:0: note: containing loop


with -O2 and -O3, while 4.8 did not do that. Probably the warning is ok, since
the test case is supposed to trigger a runtime error ("Index '5' of dimension 2
of array 'a' outside of expected range (4:1)").

However, I see three possible problems:
1) The question is why it only happens with SAVE.
2) I don't understand why the warning has 'iteration 4'. Shouldn't iteration 5
be the problem?
3) The warning appears twice.
>From gcc-bugs-return-438139-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Dec 19 14:03:18 2013
Return-Path: <gcc-bugs-return-438139-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 11579 invoked by alias); 19 Dec 2013 14:03:17 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 11543 invoked by uid 48); 19 Dec 2013 14:03:13 -0000
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
Date: Thu, 19 Dec 2013 14:03:00 -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: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: burnus at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
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
Message-ID: <bug-59561-4-lTxjRolgx6@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59561-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59561-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-12/txt/msg01794.txt.bz2
Content-length: 443

http://gcc.gnu.org/bugzilla/show_bug.cgi?idY561

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Isn't that effectively a duplicate of the P1 regression PR57904?


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

* [Bug fortran/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
@ 2013-12-19 15:21 ` rguenth at gcc dot gnu.org
  2013-12-20 17:08 ` janus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-12-19 15:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.9.0


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

* [Bug fortran/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
  2013-12-19 15:21 ` [Bug fortran/59561] " rguenth at gcc dot gnu.org
@ 2013-12-20 17:08 ` janus at gcc dot gnu.org
  2013-12-20 22:04 ` dominiq at lps dot ens.fr
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu.org @ 2013-12-20 17:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

--- Comment #2 from janus at gcc dot gnu.org ---
(In reply to Tobias Burnus from comment #1)
> Isn't that effectively a duplicate of the P1 regression PR57904?

Might well be, I'm not sure. However, the patch posted in PR 57904 comment 9
does not seem to fix the problem here ...


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

* [Bug fortran/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
  2013-12-19 15:21 ` [Bug fortran/59561] " rguenth at gcc dot gnu.org
  2013-12-20 17:08 ` janus at gcc dot gnu.org
@ 2013-12-20 22:04 ` dominiq at lps dot ens.fr
  2013-12-20 22:07 ` [Bug middle-end/59561] " dominiq at lps dot ens.fr
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-12-20 22:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-12-20
     Ever confirmed|0                           |1

--- Comment #3 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> (In reply to Tobias Burnus from comment #1)
> > Isn't that effectively a duplicate of the P1 regression PR57904?
>
> Might well be, I'm not sure. However, the patch posted in PR 57904 comment 9 
> does not seem to fix the problem here ...

I don't think it is a duplicate and I think the warning is correct (on
x86_64-apple-darwin13 I get it with/without SAVE and with/without the patch in
PR 57904 comment 9).
Too bad that the warning is emitted twice and the iteration count starts at 0
and not at one as in first (IMHO #iterations=end-start+1, i.e., 5).


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

* [Bug middle-end/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-12-20 22:04 ` dominiq at lps dot ens.fr
@ 2013-12-20 22:07 ` dominiq at lps dot ens.fr
  2014-01-17 19:42 ` law at redhat dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-12-20 22:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |law at redhat dot com
          Component|fortran                     |middle-end

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
I think it is a middle-end issue.


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

* [Bug middle-end/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2013-12-20 22:07 ` [Bug middle-end/59561] " dominiq at lps dot ens.fr
@ 2014-01-17 19:42 ` law at redhat dot com
  2014-01-22  9:36 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: law at redhat dot com @ 2014-01-17 19:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

--- Comment #5 from Jeffrey A. Law <law at redhat dot com> ---
Not a duplicate of 57904 AFAICT.


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

* [Bug middle-end/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-01-17 19:42 ` law at redhat dot com
@ 2014-01-22  9:36 ` jakub at gcc dot gnu.org
  2014-01-24 23:18 ` jakub at gcc dot gnu.org
  2014-01-31 11:20 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-22  9:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to janus from comment #0)
> with -O2 and -O3, while 4.8 did not do that. Probably the warning is ok,
> since the test case is supposed to trigger a runtime error ("Index '5' of
> dimension 2 of array 'a' outside of expected range (4:1)").

Of course the warning is correct.
> 
> However, I see three possible problems:
> 1) The question is why it only happens with SAVE.

I get the warning also without SAVE.  Furthermore, the warning is not
guaranteed for all undefined behaviors in the loop of course, only if the loop
has known constant number of iterations, no early exits and is known to trigger
selected kinds of undefined behavior in some of the iterations.

> 2) I don't understand why the warning has 'iteration 4'. Shouldn't iteration
> 5 be the problem?

This is a middle-end warning, I don't see how the middle-end could find out
that the frontend wants to count the iterations differently.

> 3) The warning appears twice.

For that I have an untested fix:

2014-01-22  Jakub Jelinek  <jakub@redhat.com>

    PR middle-end/59561
    * cfgloopmanip.c (copy_loop_info): If
    loop->warned_aggressive_loop_optimizations, make sure
    the flag is set in target loop too.

--- gcc/cfgloopmanip.c.jj    2014-01-03 11:40:33.000000000 +0100
+++ gcc/cfgloopmanip.c    2014-01-22 10:21:54.057871045 +0100
@@ -1022,6 +1022,8 @@ copy_loop_info (struct loop *loop, struc
   target->any_estimate = loop->any_estimate;
   target->nb_iterations_estimate = loop->nb_iterations_estimate;
   target->estimate_state = loop->estimate_state;
+  target->warned_aggressive_loop_optimizations
+    |= loop->warned_aggressive_loop_optimizations;
 }

 /* Copies copy of LOOP as subloop of TARGET loop, placing newly


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

* [Bug middle-end/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-01-22  9:36 ` jakub at gcc dot gnu.org
@ 2014-01-24 23:18 ` jakub at gcc dot gnu.org
  2014-01-31 11:20 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-24 23:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Jan 24 23:17:25 2014
New Revision: 207065

URL: http://gcc.gnu.org/viewcvs?rev=207065&root=gcc&view=rev
Log:
    PR middle-end/59561
    * cfgloopmanip.c (copy_loop_info): If
    loop->warned_aggressive_loop_optimizations, make sure
    the flag is set in target loop too.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgloopmanip.c


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

* [Bug middle-end/59561] [4.9 Regression] warning: iteration 4 invokes undefined behavior
  2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2014-01-24 23:18 ` jakub at gcc dot gnu.org
@ 2014-01-31 11:20 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-01-31 11:20 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59561

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed as far as we care.


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

end of thread, other threads:[~2014-01-31 11:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 13:38 [Bug fortran/59561] New: [4.9 Regression] warning: iteration 4 invokes undefined behavior janus at gcc dot gnu.org
2013-12-19 15:21 ` [Bug fortran/59561] " rguenth at gcc dot gnu.org
2013-12-20 17:08 ` janus at gcc dot gnu.org
2013-12-20 22:04 ` dominiq at lps dot ens.fr
2013-12-20 22:07 ` [Bug middle-end/59561] " dominiq at lps dot ens.fr
2014-01-17 19:42 ` law at redhat dot com
2014-01-22  9:36 ` jakub at gcc dot gnu.org
2014-01-24 23:18 ` jakub at gcc dot gnu.org
2014-01-31 11:20 ` 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).