Debian Codegraph @

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

raw
1 ! Reported as pr94070.
2 ! { dg-do run }
3 !
4 ! This program checks that passing assumed-size arrays to
5 ! and from Fortran functions with C binding works.
6 !
7
8 program testit
9 use iso_c_binding
10 implicit none
11
12 ! Assumed-size arrays are not passed by descriptor. What we'll do
13 ! for this test function is bind an assumed-rank dummy
14 ! to the assumed-size array. This is supposed to fill in the descriptor
15 ! with information about the array present at the call site.
16 interface
17 subroutine ctest (a) bind (c)
18 use iso_c_binding
19 integer(C_INT) :: a(..)
20 end subroutine
21 end interface
22
23 integer(C_INT), target :: aa(10,5:8)
24
25 ! To get an assumed-size array descriptor, we have to first pass the
26 ! fixed-size array to a Fortran function with an assumed-size dummy,
27 call ftest1 (aa)
28 call ftest2 (aa)
29 call ftest3 (aa)
30
31 contains
32 subroutine ftest1 (a)
33 use iso_c_binding
34 integer(C_INT) :: a(10,*)
35 call testf (a)
36 call testc (a)
37 end subroutine
38 subroutine ftest2 (a)
39 use iso_c_binding
40 integer(C_INT) :: a(10,5:*)
41 call testf (a)
42 call testc (a)
43 end subroutine
44 subroutine ftest3 (a) bind (c)
45 use iso_c_binding
46 integer(C_INT) :: a(10,1:*)
47 call testf (a)
48 call testc (a)
49 end subroutine
50
51 subroutine testf (a)
52 use iso_c_binding
53 integer(C_INT) :: a(..)
54 if (rank (a) .ne. 2) stop 101
55 print *, size (a, 1), size (a, 2)
56 if (size (a, 1) .ne. 10) stop 102
57 if (size (a, 2) .ne. -1) stop 103
58 if (any (lbound (a) .eq. 0)) stop 104
59 end subroutine
60
61 subroutine testc (a) bind (c)
62 use iso_c_binding
63 integer(C_INT) :: a(..)
64 if (rank (a) .ne. 2) stop 201
65 print *, size (a, 1), size (a, 2)
66 if (size (a, 1) .ne. 10) stop 202
67 if (size (a, 2) .ne. -1) stop 203
68 if (any (lbound (a) .eq. 0)) stop 204
69 end subroutine
70
71 end program