Debian Codegraph @

gcc/testsuite/gfortran.dg/do_3.F90

raw
1 ! { dg-do run }
2 ! { dg-options "-std=legacy -ffree-line-length-none -fno-range-check -fwrapv -Wzerotrip" }
3 program test
4 integer :: count
5 integer :: i
6 integer(kind=1) :: i1
7 real :: r
8
9 #define TEST_LOOP(var,from,to,step,total,test,final) \
10 count = 0 ; do var = from, to, step ; count = count + 1 ; end do ; \
11 if (count /= total) STOP 1; \
12 if (test (from, to, step, final) /= total) STOP 2
13
14 ! Integer loops
15 TEST_LOOP(i, 0, 0, 1, 1, test_i, 1)
16 TEST_LOOP(i, 0, 0, 2, 1, test_i, 2)
17 TEST_LOOP(i, 0, 0, -1, 1, test_i, -1)
18 TEST_LOOP(i, 0, 0, -2, 1, test_i, -2)
19
20 TEST_LOOP(i, 0, 1, 1, 2, test_i, 2)
21 TEST_LOOP(i, 0, 1, 2, 1, test_i, 2)
22 TEST_LOOP(i, 0, 1, 3, 1, test_i, 3)
23 TEST_LOOP(i, 0, 1, huge(0), 1, test_i, huge(0))
24 TEST_LOOP(i, 0, 1, -1, 0, test_i, 0) ! { dg-warning "executed zero times" }
25 TEST_LOOP(i, 0, 1, -2, 0, test_i, 0) ! { dg-warning "executed zero times" }
26 TEST_LOOP(i, 0, 1, -3, 0, test_i, 0) ! { dg-warning "executed zero times" }
27 TEST_LOOP(i, 0, 1, -huge(0), 0, test_i, 0) ! { dg-warning "executed zero times" }
28 TEST_LOOP(i, 0, 1, -huge(0)-1, 0, test_i, 0) ! { dg-warning "executed zero times" }
29
30 TEST_LOOP(i, 1, 0, 1, 0, test_i, 1) ! { dg-warning "executed zero times" }
31 TEST_LOOP(i, 1, 0, 2, 0, test_i, 1) ! { dg-warning "executed zero times" }
32 TEST_LOOP(i, 1, 0, 3, 0, test_i, 1) ! { dg-warning "executed zero times" }
33 TEST_LOOP(i, 1, 0, huge(0), 0, test_i, 1) ! { dg-warning "executed zero times" }
34 TEST_LOOP(i, 1, 0, -1, 2, test_i, -1)
35 TEST_LOOP(i, 1, 0, -2, 1, test_i, -1)
36 TEST_LOOP(i, 1, 0, -3, 1, test_i, -2)
37 TEST_LOOP(i, 1, 0, -huge(0), 1, test_i, 1-huge(0))
38 TEST_LOOP(i, 1, 0, -huge(0)-1, 1, test_i, -huge(0))
39
40 TEST_LOOP(i, 0, 17, 1, 18, test_i, 18)
41 TEST_LOOP(i, 0, 17, 2, 9, test_i, 18)
42 TEST_LOOP(i, 0, 17, 3, 6, test_i, 18)
43 TEST_LOOP(i, 0, 17, 4, 5, test_i, 20)
44 TEST_LOOP(i, 0, 17, 5, 4, test_i, 20)
45 TEST_LOOP(i, 17, 0, -1, 18, test_i, -1)
46 TEST_LOOP(i, 17, 0, -2, 9, test_i, -1)
47 TEST_LOOP(i, 17, 0, -3, 6, test_i, -1)
48 TEST_LOOP(i, 17, 0, -4, 5, test_i, -3)
49 TEST_LOOP(i, 17, 0, -5, 4, test_i, -3)
50
51 TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 2_1, int(huge(i1))+1, test_i1, huge(i1)+1_1)
52 TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), huge(i1), 3, test_i1, 2_1*huge(i1)-1_1)
53
54 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -2_1, int(huge(i1))+1, test_i1, -huge(i1)-2_1)
55 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1), 3, test_i1, -2_1*huge(i1))
56 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1)-1_1, 2, test_i1, -huge(i1)-2_1)
57
58 TEST_LOOP(i1, -2_1, 3_1, huge(i1), 1, test_i1, huge(i1)-2_1)
59 TEST_LOOP(i1, -2_1, 3_1, -huge(i1), 0, test_i1, -2_1) ! { dg-warning "executed zero times" }
60 TEST_LOOP(i1, 2_1, -3_1, -huge(i1), 1, test_i1, 2_1-huge(i1))
61 TEST_LOOP(i1, 2_1, -3_1, huge(i1), 0, test_i1, 2_1) ! { dg-warning "executed zero times" }
62
63 ! Real loops
64 TEST_LOOP(r, 0.0, 1.0, 0.11, 1 + int(1.0/0.11), test_r, 0.0)
65 TEST_LOOP(r, 0.0, 1.0, -0.11, 0, test_r, 0.0) ! { dg-warning "executed zero times" }
66 TEST_LOOP(r, 0.0, -1.0, 0.11, 0, test_r, 0.0) ! { dg-warning "executed zero times" }
67 TEST_LOOP(r, 0.0, -1.0, -0.11, 1 + int(1.0/0.11), test_r, 0.0)
68 TEST_LOOP(r, 0.0, 0.0, 0.11, 1, test_r, 0.0)
69 TEST_LOOP(r, 0.0, 0.0, -0.11, 1, test_r, 0.0)
70
71 #undef TEST_LOOP
72
73 contains
74
75 function test_i1 (from, to, step, final) result(res)
76 integer(kind=1), intent(in) :: from, to, step, final
77 integer(kind=1) :: i
78 integer :: res
79
80 res = 0
81 do i = from, to, step
82 res = res + 1
83 end do
84 if (i /= final) STOP 3
85 end function test_i1
86
87 function test_i (from, to, step, final) result(res)
88 integer, intent(in) :: from, to, step, final
89 integer :: i
90 integer :: res
91
92 res = 0
93 do i = from, to, step
94 res = res + 1
95 end do
96 if (i /= final) STOP 4
97 end function test_i
98
99 function test_r (from, to, step, final) result(res)
100 real, intent(in) :: from, to, step, final
101 real :: i
102 integer :: res
103
104 res = 0
105 do i = from, to, step
106 res = res + 1
107 end do
108 ! final is ignored
109 end function test_r
110
111 end program test