2 ! { dg-options "-std=legacy -ffree-line-length-none -fno-range-check -fwrapv -Wzerotrip" }
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) call abort ; \
12 if (test (from, to, step, final) /= total) call abort
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)
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" }
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))
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)
51 TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 1_1, int(huge(i1))*2+2, test_i1, huge(i1)+1_1)
52 TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), 2_1, int(huge(i1))+1, test_i1, huge(i1)+1_1)
53 TEST_LOOP(i1, -huge(i1)-1_1, huge(i1), huge(i1), 3, test_i1, 2_1*huge(i1)-1_1)
55 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -1_1, int(huge(i1))*2+2, test_i1, -huge(i1)-2_1)
56 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -2_1, int(huge(i1))+1, test_i1, -huge(i1)-2_1)
57 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1), 3, test_i1, -2_1*huge(i1))
58 TEST_LOOP(i1, huge(i1), -huge(i1)-1_1, -huge(i1)-1_1, 2, test_i1, -huge(i1)-2_1)
60 TEST_LOOP(i1, -2_1, 3_1, huge(i1), 1, test_i1, huge(i1)-2_1)
61 TEST_LOOP(i1, -2_1, 3_1, -huge(i1), 0, test_i1, -2_1) ! { dg-warning "executed zero times" }
62 TEST_LOOP(i1, 2_1, -3_1, -huge(i1), 1, test_i1, 2_1-huge(i1))
63 TEST_LOOP(i1, 2_1, -3_1, huge(i1), 0, test_i1, 2_1) ! { dg-warning "executed zero times" }
66 TEST_LOOP(r, 0.0, 1.0, 0.11, 1 + int(1.0/0.11), test_r, 0.0)
67 TEST_LOOP(r, 0.0, 1.0, -0.11, 0, test_r, 0.0) ! { dg-warning "executed zero times" }
68 TEST_LOOP(r, 0.0, -1.0, 0.11, 0, test_r, 0.0) ! { dg-warning "executed zero times" }
69 TEST_LOOP(r, 0.0, -1.0, -0.11, 1 + int(1.0/0.11), test_r, 0.0)
70 TEST_LOOP(r, 0.0, 0.0, 0.11, 1, test_r, 0.0)
71 TEST_LOOP(r, 0.0, 0.0, -0.11, 1, test_r, 0.0)
77 function test_i1 (from, to, step, final) result(res)
78 integer(kind=1), intent(in) :: from, to, step, final
86 if (i /= final) call abort
89 function test_i (from, to, step, final) result(res)
90 integer, intent(in) :: from, to, step, final
98 if (i /= final) call abort
101 function test_r (from, to, step, final) result(res)
102 real, intent(in) :: from, to, step, final
107 do i = from, to, step