Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/section-1.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-sources "section-1-c.c dump-descriptors.c" }
3 ! { dg-additional-options "-g" }
4 !
5 ! This program tests basic use of the CFI_section C library function on
6 ! a 1-dimensional non-pointer/non-allocatable array, passed as an
7 ! assumed-shape dummy.
8
9 program testit
10 use iso_c_binding
11 implicit none
12
13 interface
14 subroutine ctest (a, lb, ub, s, r) bind (c)
15 use iso_c_binding
16 integer(C_INT), target :: a(:)
17 integer(C_INT), value :: lb, ub, s
18 integer(C_INT), pointer, intent(out) :: r(:)
19 end subroutine
20
21 end interface
22
23 integer(C_INT), target :: aa(32)
24 integer :: i
25
26 ! Initialize the test array by numbering its elements.
27 do i = 1, 32
28 aa(i) = i
29 end do
30
31 ! Try some cases with non-pointer input arrays.
32 call test (aa, 1, 32, 5, 13, 2) ! basic test
33 call test (aa, 4, 35, 5, 13, 2) ! non-default lower bound
34 call test (aa, 1, 32, 32, 16, -2) ! negative step
35
36 contains
37
38 ! Test function for non-pointer array AA.
39 ! LO and HI are the bounds for the entire array.
40 ! LB, UB, and S describe the section to take, and use the
41 ! same indexing as LO and HI.
42 subroutine test (aa, lo, hi, lb, ub, s)
43 integer :: aa(lo:hi)
44 integer :: lo, hi, lb, ub, s
45
46 integer(C_INT), pointer :: rr(:)
47 integer :: i, o
48
49 ! Call the C function to put a section in rr.
50 ! The C function expects the section bounds to be 1-based.
51 nullify (rr)
52 call ctest (aa, lb - lo + 1, ub - lo + 1, s, rr)
53
54 ! Make sure the original array has not been modified.
55 do i = lo, hi
56 if (aa(i) .ne. i - lo + 1) stop 103
57 end do
58
59 ! Make sure the output array has the expected bounds and elements.
60 if (.not. associated (rr)) stop 111
61 if (lbound (rr, 1) .ne. 1) stop 112
62 if (ubound (rr, 1) .ne. (ub - lb)/s + 1) stop 113
63 o = 1
64 do i = lb, ub, s
65 if (rr(o) .ne. i - lo + 1) stop 114
66 o = o + 1
67 end do
68 end subroutine
69
70 end program
71