Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/cf-descriptor-6.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-sources "cf-descriptor-6-c.c dump-descriptors.c" }
3 !
4 ! This program tests passing the result of the CFI_section C library
5 ! routine back to Fortran. Most of the work happens on the C side.
6
7 module mm
8 use iso_c_binding
9 type, bind (c) :: m
10 integer(C_INT) :: i, j
11 end type
12
13 integer, parameter :: imax=10, jmax=5
14 integer, parameter :: ilb=2, jlb=1
15 integer, parameter :: iub=8, jub=5
16 integer, parameter :: istep=3, jstep=2
17 integer, parameter :: isize=3, jsize=3
18 end module
19
20 subroutine ftest (b) bind (c, name="ftest")
21 use iso_c_binding
22 use mm
23 type(m), pointer :: b(:,:)
24 integer :: i, j, ii, jj
25
26 if (size (b, 1) .ne. isize) stop 103
27 if (size (b, 2) .ne. jsize) stop 104
28
29 ! ii and jj iterate over the elements of b
30 ! i and j iterate over the original array
31 jj = lbound (b, 2)
32 do j = jlb, jub, jstep
33 ii = lbound (b, 1)
34 do i = ilb, iub, istep
35 if (b (ii, jj)%i .ne. i) stop 203
36 if (b (ii, jj)%j .ne. j) stop 204
37 ii = ii + 1
38 end do
39 jj = jj + 1
40 end do
41 end subroutine
42
43
44 program testit
45 use iso_c_binding
46 use mm
47 implicit none
48
49 interface
50 subroutine ctest (a, lb1, lb2, ub1, ub2, step1, step2) bind (c)
51 use iso_c_binding
52 use mm
53 type(m) :: a(:,:)
54 integer(C_INT), value :: lb1, lb2, ub1, ub2, step1, step2
55 end subroutine
56 end interface
57
58 type(m), target :: aa(imax,jmax)
59 integer :: i, j
60 do j = 1, jmax
61 do i = 1, imax
62 aa(i,j)%i = i
63 aa(i,j)%j = j
64 end do
65 end do
66
67 ! Pass the initialized array to a C function ctest, which will take
68 ! a section of it and pass it to ftest.
69
70 call ctest (aa, ilb, jlb, iub, jub, istep, jstep)
71
72 end program