[Patch,fortran] PR28914 Code inside loop hangs

Paul Thomas paulthomas2@wanadoo.fr
Sun Sep 10 04:40:00 GMT 2006


Jerry,

>
> OK to commit to 4.2?

OK - the first line of the comment needs to be dropped, since the check 
has gone. ie.


+ /* Make a temporary, store the current value in that
+ and return it, once the loop is done. */

Thanks!

Paul

PS On thinking about the PR: I suggest that you clear this one and raise 
a new one about the compile time.  The compiler does not need to walk 
the constructor in order to calculate its length and certainly should 
not expand arbitrarily long ones.


>
> Regards,
>
> Jerry
>
> 2006-09-09  Paul Thomas <pault@gcc.gnu.org>
>
>     PR fortran/28914
>     * trans-array.c (gfc_trans_array_constructor_value): Create a 
> temporary
>     loop variable to hold the current loop variable in case it is 
> modified
>     by the array constructor.
>
>
> ------------------------------------------------------------------------
>
> Index: trans-array.c
> ===================================================================
> *** trans-array.c (revision 116710)
> --- trans-array.c (working copy)
> *************** gfc_trans_array_constructor_value (stmtb
> *** 1252,1257 ****
> --- 1252,1258 ----
> tree exit_label;
> tree loopbody;
> tree tmp2;
> + tree tmp_loopvar;
>
> loopbody = gfc_finish_block (&body);
>
> *************** gfc_trans_array_constructor_value (stmtb
> *** 1260,1265 ****
> --- 1261,1272 ----
> gfc_add_block_to_block (pblock, &se.pre);
> loopvar = se.expr;
>
> + /* In case this is a variable in the function scope,
> + make a temporary, store the current value in that
> + and return it, once the loop is done. */
> + tmp_loopvar = gfc_create_var (TREE_TYPE (loopvar), "loopvar");
> + gfc_add_modify_expr (pblock, tmp_loopvar, loopvar);
> +
> /* Initialize the loop. */
> gfc_init_se (&se, NULL);
> gfc_conv_expr_val (&se, c->iterator->start);
> *************** gfc_trans_array_constructor_value (stmtb
> *** 1327,1332 ****
> --- 1334,1342 ----
> /* Add the exit label. */
> tmp = build1_v (LABEL_EXPR, exit_label);
> gfc_add_expr_to_block (pblock, tmp);
> +
> + /* Restore the original value of the loop counter. */
> + gfc_add_modify_expr (pblock, loopvar, tmp_loopvar);
> }
> }
> mpz_clear (size);
>
>
> ------------------------------------------------------------------------
>
> ! { dg-do run }
> ! Tests the fix for pr28914, in which array constructors using the loop
> ! variable within a do loop for the implied do loop of the constructor
> ! would result in a corrupted do loop counter.
> !
> ! Based on the testscase by Ed Korkven <kornkven@arsc.edu>
> !
> program pr28914
> implicit none
> integer n, i
> parameter (n = 66000) ! Problem manifests for n > 65535
> double precision a(n), summation
>
> summation = 0.0
> do i = 1, 1
> a = (/ (i, i = 1, n) /) ! This is legal and was broken
> a = sqrt(a)
> summation = SUM(a)
> enddo
> summation = abs(summation - 11303932.9138271_8)
>
> if (summation.gt.0.00001) call abort()
> end program pr28914
>
>



More information about the Fortran mailing list