From 244974bd1bb1e486361d7b4ec6fe686239e2e1f1 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Mon, 21 May 2007 22:02:26 +0000 Subject: [PATCH] re PR fortran/32027 (The "DO" variable isn't consistent after loop) PR fortran/32027 * trans-stmt.c (gfc_trans_do): Fix the value of loop variable when the loop ends. * gfortran.dg/do_3.F90: Add checks for the final value of the loop variable. From-SVN: r124923 --- gcc/fortran/ChangeLog | 6 ++ gcc/fortran/trans-stmt.c | 8 +-- gcc/testsuite/ChangeLog | 6 ++ gcc/testsuite/gfortran.dg/do_3.F90 | 131 +++++++++++++++++++------------------ 4 files changed, 83 insertions(+), 68 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 29dd7a3..ab99113 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2007-05-21 Francois-Xavier Coudert + + PR fortran/32027 + * trans-stmt.c (gfc_trans_do): Fix the value of loop variable + when the loop ends. + 2007-05-21 H.J. Lu * trans-stmt.c (gfc_trans_do): Fix a typo in comment. diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 02e8dd2..444d880 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -947,6 +947,10 @@ gfc_trans_do (gfc_code * code) gfc_add_expr_to_block (&body, tmp); } + /* Increment the loop variable. */ + tmp = build2 (PLUS_EXPR, type, dovar, step); + gfc_add_modify_expr (&body, dovar, tmp); + /* End with the loop condition. Loop until countm1 == 0. */ cond = fold_build2 (EQ_EXPR, boolean_type_node, countm1, build_int_cst (utype, 0)); @@ -955,10 +959,6 @@ gfc_trans_do (gfc_code * code) cond, tmp, build_empty_stmt ()); gfc_add_expr_to_block (&body, tmp); - /* Increment the loop variable. */ - tmp = build2 (PLUS_EXPR, type, dovar, step); - gfc_add_modify_expr (&body, dovar, tmp); - /* Decrement the loop count. */ tmp = build2 (MINUS_EXPR, utype, countm1, build_int_cst (utype, 1)); gfc_add_modify_expr (&body, countm1, tmp); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0302fc4..6de884b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-05-21 Francois-Xavier Coudert + + PR fortran/32027 + * gfortran.dg/do_3.F90: Add checks for the final value of the + loop variable. + 2007-05-21 Uros Bizjak * gcc.c-torture/execute/990127-2.x: New file. diff --git a/gcc/testsuite/gfortran.dg/do_3.F90 b/gcc/testsuite/gfortran.dg/do_3.F90 index 1e2e238..a022fc1 100644 --- a/gcc/testsuite/gfortran.dg/do_3.F90 +++ b/gcc/testsuite/gfortran.dg/do_3.F90 @@ -1,81 +1,81 @@ ! { dg-do run } -! { dg-options "-std=legacy -ffree-line-length-none" } +! { dg-options "-std=legacy -ffree-line-length-none -fno-range-check" } program test integer :: count integer :: i integer(kind=1) :: i1 real :: r -#define TEST_LOOP(var,from,to,step,total,test) \ +#define TEST_LOOP(var,from,to,step,total,test,final) \ count = 0 ; do var = from, to, step ; count = count + 1 ; end do ; \ if (count /= total) call abort ; \ - if (test (from, to, step) /= total) call abort + if (test (from, to, step, final) /= total) call abort ! Integer loops - TEST_LOOP(i, 0, 0, 1, 1, test_i) - TEST_LOOP(i, 0, 0, 2, 1, test_i) - TEST_LOOP(i, 0, 0, -1, 1, test_i) - TEST_LOOP(i, 0, 0, -2, 1, test_i) - - TEST_LOOP(i, 0, 1, 1, 2, test_i) - TEST_LOOP(i, 0, 1, 2, 1, test_i) - TEST_LOOP(i, 0, 1, 3, 1, test_i) - TEST_LOOP(i, 0, 1, huge(0), 1, test_i) - TEST_LOOP(i, 0, 1, -1, 0, test_i) - TEST_LOOP(i, 0, 1, -2, 0, test_i) - TEST_LOOP(i, 0, 1, -3, 0, test_i) - TEST_LOOP(i, 0, 1, -huge(0), 0, test_i) - TEST_LOOP(i, 0, 1, -huge(0)-1, 0, test_i) - - TEST_LOOP(i, 1, 0, 1, 0, test_i) - TEST_LOOP(i, 1, 0, 2, 0, test_i) - TEST_LOOP(i, 1, 0, 3, 0, test_i) - TEST_LOOP(i, 1, 0, huge(0), 0, test_i) - TEST_LOOP(i, 1, 0, -1, 2, test_i) - TEST_LOOP(i, 1, 0, -2, 1, test_i) - TEST_LOOP(i, 1, 0, -3, 1, test_i) - TEST_LOOP(i, 1, 0, -huge(0), 1, test_i) - TEST_LOOP(i, 1, 0, -huge(0)-1, 1, test_i) - - TEST_LOOP(i, 0, 17, 1, 18, test_i) - TEST_LOOP(i, 0, 17, 2, 9, test_i) - TEST_LOOP(i, 0, 17, 3, 6, test_i) - TEST_LOOP(i, 0, 17, 4, 5, test_i) - TEST_LOOP(i, 0, 17, 5, 4, test_i) - TEST_LOOP(i, 17, 0, -1, 18, test_i) - TEST_LOOP(i, 17, 0, -2, 9, test_i) - TEST_LOOP(i, 17, 0, -3, 6, test_i) - TEST_LOOP(i, 17, 0, -4, 5, test_i) - TEST_LOOP(i, 17, 0, -5, 4, test_i) - - TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 1_1, int(huge(i1))*2+2, test_i1) - TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 2_1, int(huge(i1))+1, test_i1) - TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), huge(i1), 3, test_i1) - - TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -1_1, int(huge(i1))*2+2, test_i1) - TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -2_1, int(huge(i1))+1, test_i1) - TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1), 3, test_i1) - TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1)-1_1, 2, test_i1) - - TEST_LOOP(i1, -2_1, 3_1, huge(i1), 1, test_i1) - TEST_LOOP(i1, -2_1, 3_1, -huge(i1), 0, test_i1) - TEST_LOOP(i1, 2_1, -3_1, -huge(i1), 1, test_i1) - TEST_LOOP(i1, 2_1, -3_1, huge(i1), 0, test_i1) + TEST_LOOP(i, 0, 0, 1, 1, test_i, 1) + TEST_LOOP(i, 0, 0, 2, 1, test_i, 2) + TEST_LOOP(i, 0, 0, -1, 1, test_i, -1) + TEST_LOOP(i, 0, 0, -2, 1, test_i, -2) + + TEST_LOOP(i, 0, 1, 1, 2, test_i, 2) + TEST_LOOP(i, 0, 1, 2, 1, test_i, 2) + TEST_LOOP(i, 0, 1, 3, 1, test_i, 3) + TEST_LOOP(i, 0, 1, huge(0), 1, test_i, huge(0)) + TEST_LOOP(i, 0, 1, -1, 0, test_i, 0) + TEST_LOOP(i, 0, 1, -2, 0, test_i, 0) + TEST_LOOP(i, 0, 1, -3, 0, test_i, 0) + TEST_LOOP(i, 0, 1, -huge(0), 0, test_i, 0) + TEST_LOOP(i, 0, 1, -huge(0)-1, 0, test_i, 0) + + TEST_LOOP(i, 1, 0, 1, 0, test_i, 1) + TEST_LOOP(i, 1, 0, 2, 0, test_i, 1) + TEST_LOOP(i, 1, 0, 3, 0, test_i, 1) + TEST_LOOP(i, 1, 0, huge(0), 0, test_i, 1) + TEST_LOOP(i, 1, 0, -1, 2, test_i, -1) + TEST_LOOP(i, 1, 0, -2, 1, test_i, -1) + TEST_LOOP(i, 1, 0, -3, 1, test_i, -2) + TEST_LOOP(i, 1, 0, -huge(0), 1, test_i, 1-huge(0)) + TEST_LOOP(i, 1, 0, -huge(0)-1, 1, test_i, -huge(0)) + + TEST_LOOP(i, 0, 17, 1, 18, test_i, 18) + TEST_LOOP(i, 0, 17, 2, 9, test_i, 18) + TEST_LOOP(i, 0, 17, 3, 6, test_i, 18) + TEST_LOOP(i, 0, 17, 4, 5, test_i, 20) + TEST_LOOP(i, 0, 17, 5, 4, test_i, 20) + TEST_LOOP(i, 17, 0, -1, 18, test_i, -1) + TEST_LOOP(i, 17, 0, -2, 9, test_i, -1) + TEST_LOOP(i, 17, 0, -3, 6, test_i, -1) + TEST_LOOP(i, 17, 0, -4, 5, test_i, -3) + TEST_LOOP(i, 17, 0, -5, 4, test_i, -3) + + TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 1_1, int(huge(i1))*2+2, test_i1, huge(i1)+1_1) + TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 2_1, int(huge(i1))+1, test_i1, huge(i1)+1_1) + TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), huge(i1), 3, test_i1, 2_1*huge(i1)-1_1) + + TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -1_1, int(huge(i1))*2+2, test_i1, -huge(i1)-2_1) + TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -2_1, int(huge(i1))+1, test_i1, -huge(i1)-2_1) + TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1), 3, test_i1, -2_1*huge(i1)) + TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1)-1_1, 2, test_i1, -huge(i1)-2_1) + + TEST_LOOP(i1, -2_1, 3_1, huge(i1), 1, test_i1, huge(i1)-2_1) + TEST_LOOP(i1, -2_1, 3_1, -huge(i1), 0, test_i1, -2_1) + TEST_LOOP(i1, 2_1, -3_1, -huge(i1), 1, test_i1, 2_1-huge(i1)) + TEST_LOOP(i1, 2_1, -3_1, huge(i1), 0, test_i1, 2_1) ! Real loops - TEST_LOOP(r, 0.0, 1.0, 0.11, 1 + int(1.0/0.11), test_r) - TEST_LOOP(r, 0.0, 1.0, -0.11, 0, test_r) - TEST_LOOP(r, 0.0, -1.0, 0.11, 0, test_r) - TEST_LOOP(r, 0.0, -1.0, -0.11, 1 + int(1.0/0.11), test_r) - TEST_LOOP(r, 0.0, 0.0, 0.11, 1, test_r) - TEST_LOOP(r, 0.0, 0.0, -0.11, 1, test_r) + TEST_LOOP(r, 0.0, 1.0, 0.11, 1 + int(1.0/0.11), test_r, 0.0) + TEST_LOOP(r, 0.0, 1.0, -0.11, 0, test_r, 0.0) + TEST_LOOP(r, 0.0, -1.0, 0.11, 0, test_r, 0.0) + TEST_LOOP(r, 0.0, -1.0, -0.11, 1 + int(1.0/0.11), test_r, 0.0) + TEST_LOOP(r, 0.0, 0.0, 0.11, 1, test_r, 0.0) + TEST_LOOP(r, 0.0, 0.0, -0.11, 1, test_r, 0.0) #undef TEST_LOOP contains - function test_i1 (from, to, step) result(res) - integer(kind=1), intent(in) :: from, to, step + function test_i1 (from, to, step, final) result(res) + integer(kind=1), intent(in) :: from, to, step, final integer(kind=1) :: i integer :: res @@ -83,10 +83,11 @@ contains do i = from, to, step res = res + 1 end do + if (i /= final) call abort end function test_i1 - function test_i (from, to, step) result(res) - integer, intent(in) :: from, to, step + function test_i (from, to, step, final) result(res) + integer, intent(in) :: from, to, step, final integer :: i integer :: res @@ -94,10 +95,11 @@ contains do i = from, to, step res = res + 1 end do + if (i /= final) call abort end function test_i - function test_r (from, to, step) result(res) - real, intent(in) :: from, to, step + function test_r (from, to, step, final) result(res) + real, intent(in) :: from, to, step, final real :: i integer :: res @@ -105,6 +107,7 @@ contains do i = from, to, step res = res + 1 end do + ! final is ignored end function test_r end program test -- 2.7.4