Debian Codegraph @

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

raw
1 ! PR 101310
2 ! { dg-do run }
3 ! { dg-additional-sources "fc-out-descriptor-7-c.c dump-descriptors.c" }
4 ! { dg-additional-options "-g" }
5 !
6 ! This program checks that returning a noncontiguous array as an intent(out)
7 ! 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 :: imax = 10, jmax=5
16
17 end module
18
19 program testit
20 use iso_c_binding
21 use mm
22 implicit none
23
24 interface
25 ! ctest points b at a section of array a defined by the
26 ! indicated bounds and steps. The returned array is 1-based.
27 subroutine ctest (a, lb1, ub1, s1, lb2, ub2, s2, b) bind (c)
28 use iso_c_binding
29 use mm
30 type(m), target :: a(:,:)
31 integer(C_INT), value :: lb1, ub1, s1, lb2, ub2, s2
32 type(m), intent(out), pointer :: b(:,:)
33 end subroutine
34 end interface
35
36 type(m), target :: a(imax, jmax)
37 type(m), pointer :: b(:,:)
38 integer :: i, j, ii, jj
39
40 do j = 1, jmax
41 do i = 1, imax
42 a(i,j)%i = i
43 a(i,j)%j = j
44 end do
45 end do
46
47 b => NULL ()
48 ! resulting array is 1-based and has shape (3,3)
49 call ctest (a, 2, 8, 3, 1, 5, 2, b)
50 if (.not. associated (b)) stop 101
51 if (rank(b) .ne. 2) stop 102
52 if (lbound (b, 1) .ne. 1) stop 103
53 if (ubound (b, 1) .ne. 3) stop 104
54 if (lbound (b, 2) .ne. 1) stop 105
55 if (ubound (b, 2) .ne. 3) stop 106
56
57 ! check that the returned array b contains the expected elements
58 ! from array a.
59 jj = lbound (b, 2)
60 do j = 1, 5, 2
61 ii = lbound (b, 1)
62 do i = 2, 8, 3
63 if (b(ii,jj)%i .ne. i) stop 107
64 if (b(ii,jj)%j .ne. j) stop 108
65 ii = ii + 1
66 end do
67 jj = jj + 1
68 end do
69
70 end program
71