| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test that arrays that may not be contiguous can be passed both ways |
| 4 |
! between Fortran subroutines with C and Fortran binding conventions. |
| 5 |
|
| 6 |
program testit |
| 7 |
use iso_c_binding |
| 8 |
implicit none |
| 9 |
|
| 10 |
integer(C_INT), target :: aa(10,5) |
| 11 |
integer(C_INT), target :: bb(10,10) |
| 12 |
|
| 13 |
integer :: i, j, n |
| 14 |
|
| 15 |
! Test both C and Fortran binding. |
| 16 |
n = 0 |
| 17 |
do j = 1, 10 |
| 18 |
do i = 1, 5 |
| 19 |
aa(j,i) = n |
| 20 |
n = n + 1 |
| 21 |
end do |
| 22 |
end do |
| 23 |
call testc (transpose (aa)) |
| 24 |
call testf (transpose (aa)) |
| 25 |
|
| 26 |
bb = -1 |
| 27 |
n = 0 |
| 28 |
do j = 1, 10 |
| 29 |
do i = 2, 10, 2 |
| 30 |
bb(i,j) = n |
| 31 |
n = n + 1 |
| 32 |
end do |
| 33 |
end do |
| 34 |
call testc (bb(2:10:2, :)) |
| 35 |
call testf (bb(2:10:2, :)) |
| 36 |
|
| 37 |
contains |
| 38 |
|
| 39 |
subroutine testc (a) bind (c) |
| 40 |
use iso_c_binding |
| 41 |
integer(C_INT), intent(in) :: a(:,:) |
| 42 |
call checkc (a) |
| 43 |
call checkf (a) |
| 44 |
end subroutine |
| 45 |
|
| 46 |
subroutine testf (a) |
| 47 |
use iso_c_binding |
| 48 |
integer(C_INT), intent(in) :: a(:,:) |
| 49 |
call checkc (a) |
| 50 |
call checkf (a) |
| 51 |
end subroutine |
| 52 |
|
| 53 |
subroutine checkc (a) bind (c) |
| 54 |
use iso_c_binding |
| 55 |
integer(C_INT), intent(in) :: a(:,:) |
| 56 |
integer :: i, j, n |
| 57 |
|
| 58 |
if (rank (a) .ne. 2) stop 101 |
| 59 |
if (size (a, 1) .ne. 5) stop 102 |
| 60 |
if (size (a, 2) .ne. 10) stop 103 |
| 61 |
|
| 62 |
n = 0 |
| 63 |
do j = 1, 10 |
| 64 |
do i = 1, 5 |
| 65 |
if (a(i,j) .ne. n) stop 104 |
| 66 |
n = n + 1 |
| 67 |
end do |
| 68 |
end do |
| 69 |
end subroutine |
| 70 |
|
| 71 |
subroutine checkf (a) |
| 72 |
use iso_c_binding |
| 73 |
integer(C_INT), intent(in) :: a(:,:) |
| 74 |
integer :: i, j, n |
| 75 |
|
| 76 |
if (rank (a) .ne. 2) stop 101 |
| 77 |
if (size (a, 1) .ne. 5) stop 102 |
| 78 |
if (size (a, 2) .ne. 10) stop 103 |
| 79 |
|
| 80 |
n = 0 |
| 81 |
do j = 1, 10 |
| 82 |
do i = 1, 5 |
| 83 |
if (a(i,j) .ne. n) stop 104 |
| 84 |
n = n + 1 |
| 85 |
end do |
| 86 |
end do |
| 87 |
end subroutine |
| 88 |
|
| 89 |
end program |