Debian Codegraph @

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

raw
1 ! PR 92621 (?)
2 ! { dg-do run }
3 ! { dg-additional-sources "fc-out-descriptor-4-c.c dump-descriptors.c" }
4 ! { dg-additional-options "-g" }
5 !
6 ! This program checks that passing an allocatable or pointer array
7 ! as an intent(out) argument to a C function called from Fortran works.
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 :: imin = 5, imax = 10, jmin = -10, jmax = -1
16
17 end module
18
19 program testit
20 use iso_c_binding
21 use mm
22 implicit none
23
24 interface
25 subroutine ctest1 (i0, ii, j0, jj, p) bind (c)
26 use iso_c_binding
27 use mm
28 integer(C_INT), value :: i0, ii, j0, jj
29 type(m), intent(out), pointer :: p(:,:)
30 end subroutine
31 subroutine ctest2 (i0, ii, j0, jj, a) bind (c)
32 use iso_c_binding
33 use mm
34 integer(C_INT), value :: i0, ii, j0, jj
35 type(m), intent(out), allocatable :: a(:,:)
36 end subroutine
37 end interface
38
39 type(m), pointer :: p(:,:)
40 type(m), allocatable :: a(:,:)
41 integer :: i, j
42
43 p => NULL ()
44 call ctest1 (imin, imax, jmin, jmax, p)
45 if (.not. associated (p)) stop 101
46 if (rank(p) .ne. 2) stop 102
47 if (lbound (p, 1) .ne. imin) stop 103
48 if (ubound (p, 1) .ne. imax) stop 104
49 if (lbound (p, 2) .ne. jmin) stop 105
50 if (ubound (p, 2) .ne. jmax) stop 106
51 do j = jmin, jmax
52 do i = imin, imax
53 if (p(i,j)%i .ne. i) stop 107
54 if (p(i,j)%j .ne. j) stop 108
55 end do
56 end do
57
58 ! The intent(out) argument is supposed to be deallocated automatically
59 ! on entry to the called function.
60 allocate (a (jmin:jmax,imin:imax))
61 if (.not. allocated (a)) stop 201
62 call ctest2 (imin, imax, jmin, jmax, a)
63 if (.not. allocated (a)) stop 201
64 if (rank(a) .ne. 2) stop 202
65 if (lbound (a, 1) .ne. imin) stop 203
66 if (ubound (a, 1) .ne. imax) stop 204
67 if (lbound (a, 2) .ne. jmin) stop 205
68 if (ubound (a, 2) .ne. jmax) stop 206
69 do j = jmin, jmax
70 do i = imin, imax
71 if (a(i,j)%i .ne. i) stop 207
72 if (a(i,j)%j .ne. j) stop 208
73 end do
74 end do
75 end program