Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/section-2p.f90

raw
1 ! PR 101310
2 ! { dg-do run }
3 ! { dg-additional-sources "section-2-c.c dump-descriptors.c" }
4 ! { dg-additional-options "-g" }
5 !
6 ! This program tests basic use of the CFI_section C library function on
7 ! a 2-dimensional pointer array.
8
9 module mm
10 use ISO_C_BINDING
11 type, bind (c) :: m
12 integer(C_INT) :: x, y
13 end type
14 end module
15
16 program testit
17 use iso_c_binding
18 use mm
19 implicit none
20
21 interface
22 subroutine ctest (p, lb0, lb1, ub0, ub1, s0, s1, r) bind (c)
23 use iso_c_binding
24 use mm
25 type(m), pointer :: p(:,:)
26 integer(C_INT), value :: lb0, lb1, ub0, ub1, s0, s1
27 type(m), pointer, intent(out) :: r(:,:)
28 end subroutine
29
30 end interface
31
32 type(m), target :: aa(10, 20)
33 integer :: i0, i1
34
35 ! Initialize the test array by numbering its elements.
36 do i1 = 1, 20
37 do i0 = 1, 10
38 aa(i0, i1)%x = i0
39 aa(i0, i1)%y = i1
40 end do
41 end do
42
43 call test (aa, 0, 0, 3, 2, 9, 14, 2, 3) ! zero lower bound
44 call test (aa, 1, 1, 4, 3, 10, 15, 2, 3) ! lower bound 1
45 call test (aa, 6, 11, 9, 13, 15, 25, 2, 3) ! other lower bound
46 call test (aa, 1, 1, 10, 15, 4, 3, -2, -3) ! negative step
47 stop
48
49 contains
50
51 ! Test function for pointer array AA.
52 ! The bounds of the array are adjusted so it is based at (LO0,LO1).
53 ! LB, UB, and S describe the section of the adjusted array to take.
54 subroutine test (aa, lo0, lo1, lb0, lb1, ub0, ub1, s0, s1)
55 use mm
56 type(m), target :: aa(1:10, 1:20)
57 integer :: lo0, lo1, lb0, lb1, ub0, ub1, s0, s1
58
59 type(m), pointer :: pp(:,:), rr(:,:)
60 integer :: i0, i1, o0, o1
61 integer :: hi0, hi1
62 hi0 = lo0 + 10 - 1
63 hi1 = lo1 + 20 - 1
64
65 pp(lo0:,lo1:) => aa
66 if (lbound (pp, 1) .ne. lo0) stop 121
67 if (lbound (pp, 2) .ne. lo1) stop 121
68 if (ubound (pp, 1) .ne. hi0) stop 122
69 if (ubound (pp, 2) .ne. hi1) stop 122
70 nullify (rr)
71 call ctest (pp, lb0, lb1, ub0, ub1, s0, s1, rr)
72
73 ! Make sure the input pointer array has not been modified.
74 if (lbound (pp, 1) .ne. lo0) stop 131
75 if (ubound (pp, 1) .ne. hi0) stop 132
76 if (lbound (pp, 2) .ne. lo1) stop 133
77 if (ubound (pp, 2) .ne. hi1) stop 134
78 do i1 = lo1, hi1
79 do i0 = lo0, hi0
80 if (pp(i0,i1)%x .ne. i0 - lo0 + 1) stop 135
81 if (pp(i0,i1)%y .ne. i1 - lo1 + 1) stop 136
82 end do
83 end do
84
85 ! Make sure the output array has the expected bounds and elements.
86 if (.not. associated (rr)) stop 141
87 if (lbound (rr, 1) .ne. 1) stop 142
88 if (lbound (rr, 2) .ne. 1) stop 142
89 if (ubound (rr, 1) .ne. (ub0 - lb0)/s0 + 1) stop 143
90 if (ubound (rr, 2) .ne. (ub1 - lb1)/s1 + 1) stop 143
91 o1 = 1
92 do i1 = lb1, ub1, s1
93 o0 = 1
94 do i0 = lb0, ub0, s0
95 if (rr(o0,o1)%x .ne. i0 - lo0 + 1) stop 144
96 if (rr(o0,o1)%y .ne. i1 - lo1 + 1) stop 144
97 o0 = o0 + 1
98 end do
99 o1 = o1 + 1
100 end do
101 end subroutine
102
103 end program
104