Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/ff-descriptor-2.f90

raw
1 ! { dg-do run }
2 !
3 ! This program checks that passing arrays as assumed-rank dummies to
4 ! and from Fortran functions with C binding works.
5
6 module mm
7 use iso_c_binding
8 type, bind (c) :: m
9 integer(C_INT) :: i, j
10 end type
11
12 integer, parameter :: imax=10, jmax=5
13 end module
14
15 program testit
16 use iso_c_binding
17 use mm
18 implicit none
19
20 type(m) :: aa(imax,jmax)
21 integer :: i, j
22 do j = 1, jmax
23 do i = 1, imax
24 aa(i,j)%i = i
25 aa(i,j)%j = j
26 end do
27 end do
28
29 call testc (aa)
30 call testf (aa)
31
32 contains
33
34 ! C binding version
35
36 subroutine checkc (a, b) bind (c)
37 use iso_c_binding
38 use mm
39 type(m) :: a(..), b(..)
40
41 if (rank (a) .ne. 2) stop 101
42 if (rank (b) .ne. 2) stop 102
43 if (size (a,1) .ne. imax) stop 103
44 if (size (a,2) .ne. jmax) stop 104
45 if (size (b,1) .ne. jmax) stop 105
46 if (size (b,2) .ne. imax) stop 106
47
48 end subroutine
49
50 ! Fortran binding version
51 subroutine checkf (a, b)
52 use iso_c_binding
53 use mm
54 type(m) :: a(..), b(..)
55
56 if (rank (a) .ne. 2) stop 201
57 if (rank (b) .ne. 2) stop 202
58 if (size (a,1) .ne. imax) stop 203
59 if (size (a,2) .ne. jmax) stop 204
60 if (size (b,1) .ne. jmax) stop 205
61 if (size (b,2) .ne. imax) stop 206
62
63 end subroutine
64
65 ! C binding version
66 subroutine testc (a) bind (c)
67 use iso_c_binding
68 use mm
69 type(m) :: a(..)
70 type(m) :: b(jmax, imax)
71
72 if (rank (a) .ne. 2) stop 301
73 if (size (a,1) .ne. imax) stop 302
74 if (size (a,2) .ne. jmax) stop 303
75
76 ! Call both the C and Fortran binding check functions
77 call checkc (a, b)
78 call checkf (a, b)
79 end subroutine
80
81 ! Fortran binding version
82 subroutine testf (a)
83 use iso_c_binding
84 use mm
85 type(m) :: a(..)
86 type(m) :: b(jmax, imax)
87
88 if (rank (a) .ne. 2) stop 401
89 if (size (a,1) .ne. imax) stop 402
90 if (size (a,2) .ne. jmax) stop 403
91
92 ! Call both the C and Fortran binding check functions
93 call checkc (a, b)
94 call checkf (a, b)
95 end subroutine
96
97 end program