public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
@ 2007-03-30 11:01 ` fxcoudert at gcc dot gnu dot org
  2007-03-30 11:49 ` fxcoudert at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-30 11:01 UTC (permalink / raw)
  To: gcc-bugs



-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|                            |4.1.3 4.2.0 4.3.0
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-30 12:01:33
               date|                            |


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


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

* [Bug fortran/31399]  New: Wrong code for do loop with large interation count
@ 2007-03-30 11:01 fxcoudert at gcc dot gnu dot org
  2007-03-30 11:01 ` [Bug fortran/31399] " fxcoudert at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-30 11:01 UTC (permalink / raw)
  To: gcc-bugs

$ cat a.f90 
  integer(kind=1) :: i
  integer(kind=8) :: c = 0

  do i = -huge(i), huge(i), 2
    c = c + 1
  end do
  print *, c
  end
$ gfortran a.f90 && ./a.out
                    0

I think it has to do with the comment on top of gfc_trans_do:

   TODO: Large loop counts
   The code above assumes the loop count fits into a signed integer kind,
   i.e. Does not work for loop counts > 2^31 for integer(kind=4) variables
   We must support the full range.

Actually, I was looking at this code, saw the comment, and designed the
testcase to trigger the bug :)  It doesn't show up using a step of 1, because
in that case we'd go into gfc_trans_simple_do. I think the loop count and other
related quantities should be made unsigned, and the loop count should be
changed from
  count = (to + step - from) / step
to something else that cannot overflow.


-- 
           Summary: Wrong code for do loop with large interation count
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fxcoudert at gcc dot gnu dot org


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
  2007-03-30 11:01 ` [Bug fortran/31399] " fxcoudert at gcc dot gnu dot org
@ 2007-03-30 11:49 ` fxcoudert at gcc dot gnu dot org
  2007-04-07 13:15 ` fxcoudert at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-30 11:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-03-30 12:49 -------
(In reply to comment #0)
> the loop count should be
> changed from
>   count = (to + step - from) / step
> to something else that cannot overflow.

I think it should be:

unsigned count = (step>0 ? to<from : to>from) ? 0 : 1 +
(unsigned)((to-from)/step)


-- 


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
  2007-03-30 11:01 ` [Bug fortran/31399] " fxcoudert at gcc dot gnu dot org
  2007-03-30 11:49 ` fxcoudert at gcc dot gnu dot org
@ 2007-04-07 13:15 ` fxcoudert at gcc dot gnu dot org
  2007-05-03 17:37 ` patchapp at dberlin dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-04-07 13:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fxcoudert at gcc dot gnu dot org  2007-04-07 14:15 -------
Created an attachment (id=13337)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13337&action=view)
Patch


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |fxcoudert at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-04-07 13:15 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-03 17:37 ` patchapp at dberlin dot org
  2007-05-07  5:53 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: patchapp at dberlin dot org @ 2007-05-03 17:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from patchapp at dberlin dot org  2007-05-03 18:37 -------
Subject: Bug number PR31399

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-05/msg00121.html


-- 


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-05-03 17:37 ` patchapp at dberlin dot org
@ 2007-05-07  5:53 ` fxcoudert at gcc dot gnu dot org
  2007-05-07  5:54 ` fxcoudert at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-07  5:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2007-05-07 06:53 -------
Subject: Bug 31399

Author: fxcoudert
Date: Mon May  7 05:53:07 2007
New Revision: 124496

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124496
Log:
        PR fortran/31399

        * trans-stmt.c (gfc_trans_do): Handle large loop counts.

        * gfortran.dg/do_3.F90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/do_3.F90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-05-07  5:53 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-07  5:54 ` fxcoudert at gcc dot gnu dot org
  2007-05-21 20:10 ` hjl at lucon dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-05-07  5:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fxcoudert at gcc dot gnu dot org  2007-05-07 06:54 -------
Fixed on mainline.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2007-05-07  5:54 ` fxcoudert at gcc dot gnu dot org
@ 2007-05-21 20:10 ` hjl at lucon dot org
  2007-05-21 20:20 ` hjl at lucon dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: hjl at lucon dot org @ 2007-05-21 20:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from hjl at lucon dot org  2007-05-21 21:10 -------
This fix miscompiles tonto in SPEC CPU 2006 on Linux/x86-64. I am checking
if Linux/ia32 is also miscompiled.


-- 

hjl at lucon dot org changed:

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


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2007-05-21 20:10 ` hjl at lucon dot org
@ 2007-05-21 20:20 ` hjl at lucon dot org
  2007-05-21 20:36 ` hjl at lucon dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: hjl at lucon dot org @ 2007-05-21 20:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from hjl at lucon dot org  2007-05-21 21:19 -------
(In reply to comment #6)
> This fix miscompiles tonto in SPEC CPU 2006 on Linux/x86-64. I am checking
> if Linux/ia32 is also miscompiled.
> 

Tonto is also miscompiled on Linux/ia32.


-- 


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2007-05-21 20:20 ` hjl at lucon dot org
@ 2007-05-21 20:36 ` hjl at lucon dot org
  2007-05-21 20:42 ` pinskia at gcc dot gnu dot org
  2007-05-21 20:54 ` hjl at lucon dot org
  10 siblings, 0 replies; 12+ messages in thread
From: hjl at lucon dot org @ 2007-05-21 20:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from hjl at lucon dot org  2007-05-21 21:36 -------
According to the comment, before the change, we performed

   [evaluate loop bounds and step]
   count = (to + step - from) / step;
   dovar = from;
   for (;;)
     {
       body;
cycle_label:
       dovar += step
       count--;
       if (count <=0) goto exit_label;
     }
exit_label:

After the change, we did

   [evaluate loop bounds and step]
   empty = (step > 0 ? to < from : to > from);
   countm1 = (to - from) / step;
   dovar = from;
   if (empty) goto exit_label;
   for (;;)
     {
       body;
cycle_label:
       dovar += step
       countm1--;
       if (countm1 ==0) goto exit_label;
     }
exit_label:

Didn't we do one loop less than before?


-- 


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2007-05-21 20:36 ` hjl at lucon dot org
@ 2007-05-21 20:42 ` pinskia at gcc dot gnu dot org
  2007-05-21 20:54 ` hjl at lucon dot org
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-21 20:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pinskia at gcc dot gnu dot org  2007-05-21 21:41 -------
(In reply to comment #6)
> This fix miscompiles tonto in SPEC CPU 2006 on Linux/x86-64. I am checking
> if Linux/ia32 is also miscompiled.

Can you file a new bug rather than reopening this one (mark it as blocking this
bug)?


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/31399] Wrong code for do loop with large interation count
  2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2007-05-21 20:42 ` pinskia at gcc dot gnu dot org
@ 2007-05-21 20:54 ` hjl at lucon dot org
  10 siblings, 0 replies; 12+ messages in thread
From: hjl at lucon dot org @ 2007-05-21 20:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from hjl at lucon dot org  2007-05-21 21:54 -------
(In reply to comment #9)
> (In reply to comment #6)
> > This fix miscompiles tonto in SPEC CPU 2006 on Linux/x86-64. I am checking
> > if Linux/ia32 is also miscompiled.
> 
> Can you file a new bug rather than reopening this one (mark it as blocking this
> bug)?
>

I don't have a small testcase. It will take a while to find a small testcase.


-- 


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


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

end of thread, other threads:[~2007-05-21 20:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-30 11:01 [Bug fortran/31399] New: Wrong code for do loop with large interation count fxcoudert at gcc dot gnu dot org
2007-03-30 11:01 ` [Bug fortran/31399] " fxcoudert at gcc dot gnu dot org
2007-03-30 11:49 ` fxcoudert at gcc dot gnu dot org
2007-04-07 13:15 ` fxcoudert at gcc dot gnu dot org
2007-05-03 17:37 ` patchapp at dberlin dot org
2007-05-07  5:53 ` fxcoudert at gcc dot gnu dot org
2007-05-07  5:54 ` fxcoudert at gcc dot gnu dot org
2007-05-21 20:10 ` hjl at lucon dot org
2007-05-21 20:20 ` hjl at lucon dot org
2007-05-21 20:36 ` hjl at lucon dot org
2007-05-21 20:42 ` pinskia at gcc dot gnu dot org
2007-05-21 20:54 ` hjl at lucon dot 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).