| 1 |
! Reported as pr94070. |
| 2 |
! { dg-do run } |
| 3 |
! { dg-additional-sources "cf-out-descriptor-6-c.c dump-descriptors.c" } |
| 4 |
! { dg-additional-options "-g" } |
| 5 |
! |
| 6 |
! This program checks passing an assumed-size array as an intent(out) |
| 7 |
! argument to a bind (c) Fortran function from both C and Fortran. |
| 8 |
|
| 9 |
! Assumed-size arrays are not passed by descriptor. What we'll do |
| 10 |
! for this test function is pass the assumed-size array as the actual |
| 11 |
! argument corresponding to an assumed-rank dummy. This is supposed to |
| 12 |
! fill in the descriptor with information about the array present at |
| 13 |
! the call site. |
| 14 |
|
| 15 |
subroutine ftest (a, n) bind (c, name="ftest") |
| 16 |
use iso_c_binding |
| 17 |
integer(C_INT), intent(out) :: a(..) |
| 18 |
integer(C_INT), value :: n |
| 19 |
integer :: i |
| 20 |
|
| 21 |
! TS 29113 |
| 22 |
! 6.4.2 SIZE |
| 23 |
! (1) for an assumed-rank object that is associated with an |
| 24 |
! assumed-size array, the result has the value −1 if DIM is |
| 25 |
! present and equal to the rank of ARRAY |
| 26 |
if (rank (a) .ne. 1) stop 102 |
| 27 |
if (size (a, rank (a)) .ne. -1) stop 100 |
| 28 |
if (lbound (a, rank (a)) .ne. 1) stop 101 |
| 29 |
|
| 30 |
select rank (a) |
| 31 |
rank (*) |
| 32 |
do i = 1, n |
| 33 |
a(i) = i |
| 34 |
end do |
| 35 |
rank default |
| 36 |
stop 102 |
| 37 |
end select |
| 38 |
end subroutine |
| 39 |
|
| 40 |
program testit |
| 41 |
use iso_c_binding |
| 42 |
implicit none |
| 43 |
|
| 44 |
interface |
| 45 |
subroutine ctest (a, n) bind (c, name="ctest") |
| 46 |
use iso_c_binding |
| 47 |
integer(C_INT), intent(out) :: a(..) |
| 48 |
integer(C_INT), value :: n |
| 49 |
end subroutine |
| 50 |
subroutine ftest (a, n) bind (c, name="ftest") |
| 51 |
use iso_c_binding |
| 52 |
integer(C_INT), intent(out) :: a(..) |
| 53 |
integer(C_INT), value :: n |
| 54 |
end subroutine |
| 55 |
end interface |
| 56 |
|
| 57 |
integer(C_INT), target :: aa(10) |
| 58 |
|
| 59 |
! To get an assumed-size array descriptor, we have to first pass the |
| 60 |
! fixed-size array to a Fortran function with an assumed-size dummy, |
| 61 |
call ftest1 (aa, 10) ! calls ftest |
| 62 |
call ftest2 (aa, 10) ! has c binding, calls ftest |
| 63 |
call ftest3 (aa, 10) ! calls ctest -> ftest |
| 64 |
call ftest4 (aa, 10) ! has c binding, calls ctest -> ftest |
| 65 |
|
| 66 |
contains |
| 67 |
|
| 68 |
subroutine ftest1 (a, n) |
| 69 |
use iso_c_binding |
| 70 |
integer(C_INT), intent(out) :: a(*) |
| 71 |
integer(C_INT), value :: n |
| 72 |
integer :: i |
| 73 |
a(1:n) = 0 |
| 74 |
call ftest (a, n) |
| 75 |
do i = 1, n |
| 76 |
if (a (i) .ne. i) stop 200 |
| 77 |
end do |
| 78 |
end subroutine |
| 79 |
|
| 80 |
subroutine ftest2 (a, n) bind (c) |
| 81 |
use iso_c_binding |
| 82 |
integer(C_INT), intent(out) :: a(*) |
| 83 |
integer(C_INT), value :: n |
| 84 |
integer :: i |
| 85 |
a(1:n) = 0 |
| 86 |
call ftest (a, n) |
| 87 |
do i = 1, n |
| 88 |
if (a (i) .ne. i) stop 201 |
| 89 |
end do |
| 90 |
end subroutine |
| 91 |
|
| 92 |
subroutine ftest3 (a, n) |
| 93 |
use iso_c_binding |
| 94 |
integer(C_INT), intent(out) :: a(*) |
| 95 |
integer(C_INT), value :: n |
| 96 |
integer :: i |
| 97 |
a(1:n) = 0 |
| 98 |
call ctest (a, n) |
| 99 |
do i = 1, n |
| 100 |
if (a (i) .ne. i) stop 202 |
| 101 |
end do |
| 102 |
end subroutine |
| 103 |
|
| 104 |
subroutine ftest4 (a, n) bind (c) |
| 105 |
use iso_c_binding |
| 106 |
integer(C_INT), intent(out) :: a(*) |
| 107 |
integer(C_INT), value :: n |
| 108 |
integer :: i |
| 109 |
a(1:n) = 0 |
| 110 |
call ctest (a, n) |
| 111 |
do i = 1, n |
| 112 |
if (a (i) .ne. i) stop 203 |
| 113 |
end do |
| 114 |
end subroutine |
| 115 |
end program |