Debian Codegraph @

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

raw
1 ! { dg-do run }
2 ! { dg-additional-sources "cf-descriptor-4-c.c dump-descriptors.c" }
3 ! { dg-additional-options "-g" }
4 !
5 ! This program checks that building a descriptor for an allocatable
6 ! or pointer array argument in C works and that you can use it to call
7 ! back into a Fortran function declared to have c binding.
8
9 module mm
10 use iso_c_binding
11 type, bind (c) :: m
12 integer(C_INT) :: i, j
13 end type
14
15 integer(C_INT), parameter :: imax=3, jmax=6
16 end module
17
18 subroutine ftest (a, b, initp) bind (c, name="ftest")
19 use iso_c_binding
20 use mm
21 type(m), allocatable :: a(:,:)
22 type(m), pointer :: b(:,:)
23 integer(C_INT), value :: initp
24 integer :: i, j
25
26 if (rank(a) .ne. 2) stop 101
27 if (rank(b) .ne. 2) stop 101
28
29 if (initp .ne. 0 .and. .not. allocated(a)) stop 102
30 if (initp .eq. 0 .and. allocated(a)) stop 103
31 if (initp .ne. 0 .and. .not. associated(b)) stop 104
32 if (initp .eq. 0 .and. associated(b)) stop 105
33
34 if (initp .ne. 0) then
35 if (lbound (a, 1) .ne. 1) stop 201
36 if (lbound (a, 2) .ne. 1) stop 202
37 if (lbound (b, 2) .ne. 1) stop 203
38 if (lbound (b, 1) .ne. 1) stop 204
39 if (ubound (a, 1) .ne. imax) stop 205
40 if (ubound (a, 2) .ne. jmax) stop 206
41 if (ubound (b, 2) .ne. imax) stop 207
42 if (ubound (b, 1) .ne. jmax) stop 208
43
44 do i = 1, imax
45 do j = 1, jmax
46 if (a(i,j)%i .ne. i) stop 301
47 if (a(i,j)%j .ne. j) stop 302
48 if (b(j,i)%i .ne. i) stop 303
49 if (b(j,i)%j .ne. j) stop 303
50 end do
51 end do
52
53 end if
54 end subroutine
55
56
57 program testit
58 use iso_c_binding
59 use mm
60 implicit none
61
62 interface
63 subroutine ctest (i, j) bind (c)
64 use iso_c_binding
65 integer(C_INT), value :: i, j
66 end subroutine
67 end interface
68
69 ! ctest will call ftest with both an unallocated and allocated argument.
70
71 call ctest (imax, jmax)
72
73 end program