Hi all,
Attached patch fixes PR31399 by changing the code we generate for DO
loops. Except for simple loops (with step 1 or -1), we compute the loop
count and iterate by decreasing it until it reaches zero. However, for
the largest loop, the count can overflow the corresponding unsigned
type. (For example, the loop going from -huge(0)-1 to huge(0) has
2*huge(0)+2 elements, while the largest unsigned integer of this kind is
2*huge(0)+1.) The solution is to store the loop count minus one,
instead, and reorder the generated code.
Bootstrapped and regtested on i686-linux, it comes with a testcase for
both integer and real loops. OK for mainline? (It's a regression wrt
g77, but it affects very little user code, so I don't think it's worth a
backport.)
FX
:ADDPATCH fortran:
2007-05-02 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/31399
* trans-stmt.c (gfc_trans_do): Handle large loop counts.
2007-05-02 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/31399
* gfortran.dg/do_3.F90: New test.