| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-sources "contiguous-1-c.c dump-descriptors.c" } |
| 3 |
! { dg-additional-options "-g" } |
| 4 |
! |
| 5 |
! TS 29113 |
| 6 |
! 8.7 In an invocation of an interoperable procedure whose Fortran |
| 7 |
! interface has an assumed-shape or assumed-rank dummy argument with the |
| 8 |
! CONTIGUOUS attribute, the associated effective argument may be an |
| 9 |
! array that is not contiguous or the address of a C descriptor for such |
| 10 |
! an array. If the procedure is invoked from Fortran or the procedure is |
| 11 |
! a Fortran procedure, the Fortran processor will handle the difference |
| 12 |
! in contiguity. If the procedure is invoked from C and the procedure is |
| 13 |
! a C procedure, the C code within the procedure shall be prepared to |
| 14 |
! handle the situation of receiving a discontiguous argument. |
| 15 |
! |
| 16 |
! This program tests the cases where Fortran code passes a non-contiguous |
| 17 |
! array section to a C function whose interface has the contiguous |
| 18 |
! attribute. |
| 19 |
|
| 20 |
program testit |
| 21 |
use iso_c_binding |
| 22 |
implicit none |
| 23 |
|
| 24 |
interface |
| 25 |
! ctest1 and ctest2 both negate the elements of their input array. |
| 26 |
subroutine ctest1 (a) bind (c) |
| 27 |
use iso_c_binding |
| 28 |
integer(C_INT), contiguous :: a(:) |
| 29 |
end subroutine |
| 30 |
subroutine ctest2 (a) bind (c) |
| 31 |
use iso_c_binding |
| 32 |
integer(C_INT), contiguous :: a(..) |
| 33 |
end subroutine |
| 34 |
end interface |
| 35 |
|
| 36 |
integer(C_INT) :: aa(32) |
| 37 |
integer :: i |
| 38 |
|
| 39 |
! assumed-shape |
| 40 |
do i = 1, 32 |
| 41 |
aa(i) = i |
| 42 |
end do |
| 43 |
call ctest1 (aa(4:12:2)) |
| 44 |
do i = 1, 32 |
| 45 |
if (i .ge. 4 .and. i .le. 12 .and. mod (i-4,2) .eq. 0) then |
| 46 |
if (aa (i) .ne. -i) stop 101 |
| 47 |
else |
| 48 |
if (aa (i) .ne. i) stop 102 |
| 49 |
end if |
| 50 |
end do |
| 51 |
|
| 52 |
! assumed-rank |
| 53 |
do i = 1, 32 |
| 54 |
aa(i) = i |
| 55 |
end do |
| 56 |
call ctest2 (aa(7:19:3)) |
| 57 |
do i = 1, 32 |
| 58 |
if (i .ge. 7 .and. i .le. 19 .and. mod (i-7,3) .eq. 0) then |
| 59 |
if (aa (i) .ne. -i) stop 201 |
| 60 |
else |
| 61 |
if (aa (i) .ne. i) stop 202 |
| 62 |
end if |
| 63 |
end do |
| 64 |
|
| 65 |
end program |
| 66 |
|
| 67 |
|