public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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

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