Debian Codegraph @

gcc/testsuite/gfortran.dg/reduce_4.f90

raw
1 ! { dg-do run }
2 !
3 ! PR119540 comment2: REDUCE was getting the shape wrong. This testcase also
4 ! verifies that the longest possible name for the OPERATION wrapper function
5 ! is catered for.
6 !
7 ! Contributed by Harald Anlauf <[email protected]>
8 !
9 program p2345678901234567890123456789012345678901234567890123456789_123
10 implicit none
11 integer, parameter :: n = 3
12 integer, parameter :: vec(n) = [2, 5, 10]
13 integer, parameter :: mat(n,2) = reshape([vec,2*vec],[n,2])
14 integer :: mat_shape(2), reduce_shape(1), r
15 integer, dimension(:), allocatable :: res1
16
17 mat_shape = shape (mat)
18 reduce_shape = shape (reduce (mat, add, 1), 1)
19 if (reduce_shape(1) /= mat_shape(2)) stop 1
20
21 reduce_shape = shape (reduce (mat, add, 1), 1)
22 if (reduce_shape(1) /= mat_shape(2)) stop 2
23
24 res1 = reduce (mat, add, 1)
25 if (any (res1 /= [17, 34])) stop 3
26
27 res1 = reduce (mat, add, 2)
28 if (any (res1 /= [6, 15, 30])) stop 4
29
30 r = reduce (vec, &
31 o2345678901234567890123456789012345678901234567890123456789_123)
32 if (r /= 17) stop 5
33
34 deallocate (res1)
35 contains
36 pure function add(i,j) result(sum_ij)
37 integer, intent(in) :: i, j
38 integer :: sum_ij
39 sum_ij = i + j
40 end function add
41
42 pure function o2345678901234567890123456789012345678901234567890123456789_123 (i, j) &
43 result (sum)
44 integer, intent(in) :: i, j
45 integer :: sum
46 sum = i + j
47 end function
48 end