summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/do_3.F90
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gfortran.dg/do_3.F90
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gfortran.dg/do_3.F90')
-rw-r--r--gcc/testsuite/gfortran.dg/do_3.F90113
1 files changed, 113 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/do_3.F90 b/gcc/testsuite/gfortran.dg/do_3.F90
new file mode 100644
index 000000000..67723a508
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/do_3.F90
@@ -0,0 +1,113 @@
+! { dg-do run }
+! { dg-options "-std=legacy -ffree-line-length-none -fno-range-check -fwrapv" }
+program test
+ integer :: count
+ integer :: i
+ integer(kind=1) :: i1
+ real :: r
+
+#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, final) /= total) call abort
+
+ ! Integer loops
+ 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) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 0, 1, -2, 0, test_i, 0) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 0, 1, -3, 0, test_i, 0) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 0, 1, -huge(0), 0, test_i, 0) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 0, 1, -huge(0)-1, 0, test_i, 0) ! { dg-warning "executed zero times" }
+
+ TEST_LOOP(i, 1, 0, 1, 0, test_i, 1) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 1, 0, 2, 0, test_i, 1) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 1, 0, 3, 0, test_i, 1) ! { dg-warning "executed zero times" }
+ TEST_LOOP(i, 1, 0, huge(0), 0, test_i, 1) ! { dg-warning "executed zero times" }
+ 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) ! { dg-warning "executed zero times" }
+ 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) ! { dg-warning "executed zero times" }
+
+ ! Real loops
+ 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) ! { dg-warning "executed zero times" }
+ TEST_LOOP(r, 0.0, -1.0, 0.11, 0, test_r, 0.0) ! { dg-warning "executed zero times" }
+ 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, final) result(res)
+ integer(kind=1), intent(in) :: from, to, step, final
+ integer(kind=1) :: i
+ integer :: res
+
+ res = 0
+ 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, final) result(res)
+ integer, intent(in) :: from, to, step, final
+ integer :: i
+ integer :: res
+
+ res = 0
+ 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, final) result(res)
+ real, intent(in) :: from, to, step, final
+ real :: i
+ integer :: res
+
+ res = 0
+ do i = from, to, step
+ res = res + 1
+ end do
+ ! final is ignored
+ end function test_r
+
+end program test