| 1 |
! PR 101308 |
| 2 |
! { dg-do run } |
| 3 |
! { dg-additional-sources "fc-out-descriptor-3-c.c dump-descriptors.c" } |
| 4 |
! { dg-additional-options "-g" } |
| 5 |
! |
| 6 |
! This program checks that passing an allocatable or pointer scalar |
| 7 |
! as an intent(out) 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 :: iinit = 42, jinit = 12345 |
| 16 |
|
| 17 |
end module |
| 18 |
|
| 19 |
program testit |
| 20 |
use iso_c_binding |
| 21 |
use mm |
| 22 |
implicit none |
| 23 |
|
| 24 |
interface |
| 25 |
subroutine ctest1 (ii, jj, p) bind (c) |
| 26 |
use iso_c_binding |
| 27 |
use mm |
| 28 |
integer(C_INT), value :: ii, jj |
| 29 |
type(m), intent(out), pointer :: p |
| 30 |
end subroutine |
| 31 |
subroutine ctest2 (ii, jj, a) bind (c) |
| 32 |
use iso_c_binding |
| 33 |
use mm |
| 34 |
integer(C_INT), value :: ii, jj |
| 35 |
type(m), intent(out), allocatable :: a |
| 36 |
end subroutine |
| 37 |
end interface |
| 38 |
|
| 39 |
type(m), pointer :: p |
| 40 |
type(m), allocatable :: a |
| 41 |
|
| 42 |
! The association status of the intent(out) pointer argument is supposed |
| 43 |
! to become undefined on entry to the called procedure. |
| 44 |
p => NULL () |
| 45 |
call ctest1 (iinit, jinit, p) |
| 46 |
if (.not. associated (p)) stop 101 |
| 47 |
if (p%i .ne. iinit) stop 102 |
| 48 |
if (p%j .ne. jinit) stop 103 |
| 49 |
|
| 50 |
! The intent(out) argument is supposed to be deallocated automatically |
| 51 |
! on entry to the called function. |
| 52 |
allocate (a) |
| 53 |
a%i = 0 |
| 54 |
a%j = 0 |
| 55 |
call ctest2 (iinit, jinit, a) |
| 56 |
if (.not. allocated (a)) stop 201 |
| 57 |
if (a%i .ne. iinit) stop 202 |
| 58 |
if (a%j .ne. jinit) stop 203 |
| 59 |
end program |