This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/31399] New: Wrong code for do loop with large interation count
- From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Mar 2007 11:01:02 -0000
- Subject: [Bug fortran/31399] New: Wrong code for do loop with large interation count
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
$ 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