This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/54932] Invalid loop code generated by Fortran FE for loops with bounds in HIGH(type)
- From: "dominiq at lps dot ens.fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 12 Feb 2013 18:21:53 +0000
- Subject: [Bug fortran/54932] Invalid loop code generated by Fortran FE for loops with bounds in HIGH(type)
- Auto-submitted: auto-generated
- References: <bug-54932-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54932
--- Comment #14 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2013-02-12 18:21:53 UTC ---
(In reply to comment #13)
> Please also split the testcase - it contains
> several tests and only one has invalid overflow.
Actually there are three of them
(a)
program do_1
implicit none
integer i, j
! limit=HUGE(i), step 1
j = 0
do i = HUGE(i) - 10, HUGE(i), 1
j = j + 1
end do
! print *, i
if (j .ne. 11) call abort
end program
(b)
program do_1
implicit none
integer i, j
! limit=HUGE(i), step > 1
j = 0
do i = HUGE(i) - 10, HUGE(i), 2
j = j + 1
end do
if (j .ne. 6) call abort
! print *, i
end program
(c)
program do_1
implicit none
integer i, j
! limit=HUGE(i), step > 1
j = 0
do i = HUGE(i) - 9, HUGE(i), 2
j = j + 1
end do
! print *, i
if (j .ne. 5) call abort
end program
Only (a) aborts and only if the PRINT is commented. (b) and (c) don't abort
even in the PRINT is uncommented.
Finally I have tested
program do_1
implicit none
integer i, j, i1, i2, i3, j1, j2, j3
! limit=HUGE(i), step 1
j = 0
do i = HUGE(i) - 10, HUGE(i), 1
j = j + 1
end do
i1 = i
j1 = j
! if (j .ne. 11) call abort
! limit=HUGE(i), step > 1
j = 0
do i = HUGE(i) - 10, HUGE(i), 2
j = j + 1
end do
i2 = i
j2 = j
! if (j .ne. 6) call abort
j = 0
do i = HUGE(i) - 9, HUGE(i), 2
j = j + 1
end do
i3 = i
j3 = j
! if (j .ne. 5) call abort
! Same again, but unknown loop step
if (test1(10, 1) .ne. 11) call abort
if (test1(10, 2) .ne. 6) call abort
if (test1(9, 2) .ne. 5) call abort
print *, i3, j3
if (j3 .ne. 5) call abort
print *, i2, j2
if (j2 .ne. 6) call abort
print *, i1, j1
if (j1 .ne. 11) call abort
contains
! Returns the number of iterations performed.
function test1(r, step)
implicit none
integer test1, r, step
integer k, n
k = 0
do n = HUGE(n) - r, HUGE(n), step
k = k + 1
end do
print *, n, k
test1 = k
end function
end program
which shows that a contained function is enough to hide the invalid behavior,
which detected for the three loops when put together.