Debian Codegraph @

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

raw
1 ! { dg-do run }
2 ! { dg-additional-sources "cf-descriptor-8-c.c dump-descriptors.c" }
3 !
4 ! This program tests passing the result of the CFI_setpointer C library
5 ! function 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 end module
15
16 subroutine ftest1 (a, lb1, lb2) bind (c, name="ftest1")
17 use iso_c_binding
18 use mm
19 type(m), pointer :: a(:,:)
20 integer(C_INT), value :: lb1, lb2
21 integer :: i, j, ii, jj
22
23 if (size (a,1) .ne. imax) stop 101
24 if (size (a,2) .ne. jmax) stop 102
25 if (lbound (a, 1) .ne. lb1) stop 103
26 if (lbound (a, 2) .ne. lb2) stop 104
27
28 if (.not. associated (a)) stop 105
29
30 jj = lb2
31 do j = 1, jmax
32 ii = lb1
33 do i = 1, imax
34 if (a(ii,jj)%i .ne. i) stop 201
35 if (a(ii,jj)%j .ne. j) stop 202
36 ii = ii + 1
37 end do
38 jj = jj + 1
39 end do
40 end subroutine
41
42 subroutine ftest2 (a) bind (c, name="ftest2")
43 use iso_c_binding
44 use mm
45 type(m), pointer :: a(:,:)
46
47 if (associated (a)) stop 301
48 end subroutine
49
50 program testit
51 use iso_c_binding
52 use mm
53 implicit none
54
55 interface
56 subroutine ctest (a) bind (c)
57 use iso_c_binding
58 use mm
59 type(m) :: a(:,:)
60 end subroutine
61 end interface
62
63 type(m), target :: aa(imax,jmax)
64 integer :: i, j
65 do j = 1, jmax
66 do i = 1, imax
67 aa(i,j)%i = i
68 aa(i,j)%j = j
69 end do
70 end do
71
72 ! Pass the initialized array to a C function ctest, which will use it
73 ! as the target of a pointer array with various bounds, calling
74 ! ftest1 and ftest2 to check that CFI_setpointer did the right thing.
75
76 call ctest (aa)
77
78 end program