diff options
author | fxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-21 22:02:26 +0000 |
---|---|---|
committer | fxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-05-21 22:02:26 +0000 |
commit | 92a4c76352df940c1e3aa9bd0f6bee004d604e64 (patch) | |
tree | c08086a86a965927acdec1f1d221c9d3afc7c69d /gcc | |
parent | a205ddf73004a62ecc1db036077da83e117d404e (diff) | |
download | gcc-92a4c76352df940c1e3aa9bd0f6bee004d604e64.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@124923 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fortran/trans-stmt.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | 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 29dd7a34da3..ab99113b8f6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2007-05-21 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> + + 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 <hongjiu.lu@intel.com> * 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 02e8dd26b84..444d880964f 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 0302fc4ac87..6de884bd588 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-05-21 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> + + PR fortran/32027 + * gfortran.dg/do_3.F90: Add checks for the final value of the + loop variable. + 2007-05-21 Uros Bizjak <ubizjak@gmail.com> * 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 1e2e238bf7e..a022fc1fa8c 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 |