public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Fortran loops
@ 2016-06-27 19:37 Dominique d'Humières
  2016-06-27 19:43 ` Adam Hirst
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Dominique d'Humières @ 2016-06-27 19:37 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: fortran, williamclodius, ahirst

IIRC this has already been discussed in the past (gfortran.dg/do_1.f90). 
The Fortran standard requires that the variable i is equal to array(2)+1 on the loop exit, which causes an overflow if array(2) is equal to huge(i). 
So the code is invalid when b(2) = huge(x), but I don’t see why the overflow of the exit value should lead to an infinite loop.
Dominique
> On Jun 27, 2016, at 6:56 PM, Jan Hubicka <hubicka@ucw.cz> wrote:
> 
> Hello,
> I have a Fortran question.  The following program loops infinitly when compiled
> with ifort -O0, while it does the expected number of iterations with gfortran.
> The issue is that we do produce quite ineffective code to deal with
> side cases like this.
> 
> is the program bellow valid and expected to terminate?  If so I guess we want
> to have it as a testcase.
> 
> Thanks,
> Honza
> 
> program test_program
> integer(4) :: b(2), a(22), x
> integer(8) :: suma
> 
> b(1) = huge(x)-10
> b(2) = huge(x)
> 
> call test2(b, suma)
> print *,suma
> 
> end program test_program
> function test2(array, s)
>  integer(4) :: i, block(9), array(2)
>  integer (8) :: s
>  s = 1
> 
>  do i = array(1), array(2)
>      s = s + 1
>  end do
> 
> end function test2
> 

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

end of thread, other threads:[~2016-07-01 12:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-27 19:37 Fortran loops Dominique d'Humières
2016-06-27 19:43 ` Adam Hirst
2016-06-27 20:05 ` Dominique d'Humières
2016-06-27 20:22 ` FX
2016-06-27 21:25   ` William Clodius
2016-06-28 12:10 ` Jan Hubicka
2016-06-28 13:50   ` Richard Biener
2016-06-28 13:56     ` Jan Hubicka
2016-06-30 11:17       ` [PATCH, RFC] Introduce -ffast-do-loop flag Martin Liška
2016-06-30 11:43         ` Richard Biener
2016-06-30 15:10           ` Martin Liška
2016-06-30 19:10         ` FX
2016-06-30 20:23           ` Mikael Morin
2016-07-01 12:30             ` Martin Liška

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