| 1 |
! PR 101305 |
| 2 |
! PR 100917 |
| 3 |
! xfailed due to PR 101308 |
| 4 |
! { dg-do run } |
| 5 |
! { dg-additional-sources "typecodes-scalar-basic-c.c dump-descriptors.c" } |
| 6 |
! { dg-additional-options "-g" } |
| 7 |
! |
| 8 |
! This program tests that kind constants in the ISO_C_BINDING |
| 9 |
! module result in the right type field in arguments passed by descriptor, |
| 10 |
! also matching the size of the corresponding C type. We use pointers |
| 11 |
! to force the use of a descriptor. |
| 12 |
! |
| 13 |
! Some types are tested in their own testcases to allow conditionalization |
| 14 |
! for target-specific support or xfailing to track bugs. |
| 15 |
|
| 16 |
module mm |
| 17 |
use iso_c_binding |
| 18 |
|
| 19 |
type, bind (c) :: s |
| 20 |
integer(C_INT) :: i, j |
| 21 |
end type |
| 22 |
end module |
| 23 |
|
| 24 |
program testit |
| 25 |
use iso_c_binding |
| 26 |
use mm |
| 27 |
implicit none |
| 28 |
|
| 29 |
interface |
| 30 |
|
| 31 |
subroutine ctest_int1 (arg_int, arg_short, arg_long, arg_long_long, & |
| 32 |
arg_signed_char) bind (c) |
| 33 |
use iso_c_binding |
| 34 |
integer(C_INT), pointer :: arg_int |
| 35 |
integer(C_SHORT), pointer :: arg_short |
| 36 |
integer(C_LONG), pointer :: arg_long |
| 37 |
integer(C_LONG_LONG), pointer :: arg_long_long |
| 38 |
integer(C_SIGNED_CHAR), pointer :: arg_signed_char |
| 39 |
end subroutine |
| 40 |
|
| 41 |
subroutine ctest_int2 (arg_int8, arg_int16, arg_int32, arg_int64) bind (c) |
| 42 |
use iso_c_binding |
| 43 |
integer(C_INT8_T), pointer :: arg_int8 |
| 44 |
integer(C_INT16_T), pointer :: arg_int16 |
| 45 |
integer(C_INT32_T), pointer :: arg_int32 |
| 46 |
integer(C_INT64_T), pointer :: arg_int64 |
| 47 |
end subroutine |
| 48 |
|
| 49 |
subroutine ctest_int3 (arg_least8, arg_least16, arg_least32, & |
| 50 |
arg_least64) bind (c) |
| 51 |
use iso_c_binding |
| 52 |
integer(C_INT_LEAST8_T), pointer :: arg_least8 |
| 53 |
integer(C_INT_LEAST16_T), pointer :: arg_least16 |
| 54 |
integer(C_INT_LEAST32_T), pointer :: arg_least32 |
| 55 |
integer(C_INT_LEAST64_T), pointer :: arg_least64 |
| 56 |
end subroutine |
| 57 |
|
| 58 |
subroutine ctest_int4 (arg_fast8, arg_fast16, arg_fast32, & |
| 59 |
arg_fast64) bind (c) |
| 60 |
use iso_c_binding |
| 61 |
integer(C_INT_FAST8_T), pointer :: arg_fast8 |
| 62 |
integer(C_INT_FAST16_T), pointer :: arg_fast16 |
| 63 |
integer(C_INT_FAST32_T), pointer :: arg_fast32 |
| 64 |
integer(C_INT_FAST64_T), pointer :: arg_fast64 |
| 65 |
end subroutine |
| 66 |
|
| 67 |
subroutine ctest_int5 (arg_size, arg_intmax, arg_intptr, & |
| 68 |
arg_ptrdiff) bind (c) |
| 69 |
use iso_c_binding |
| 70 |
integer(C_SIZE_T), pointer :: arg_size |
| 71 |
integer(C_INTMAX_T), pointer :: arg_intmax |
| 72 |
integer(C_INTPTR_T), pointer :: arg_intptr |
| 73 |
integer(C_PTRDIFF_T), pointer :: arg_ptrdiff |
| 74 |
end subroutine |
| 75 |
|
| 76 |
subroutine ctest_real (arg_float, arg_double) bind (c) |
| 77 |
use iso_c_binding |
| 78 |
real(C_FLOAT), pointer :: arg_float |
| 79 |
real(C_DOUBLE), pointer :: arg_double |
| 80 |
end subroutine |
| 81 |
|
| 82 |
subroutine ctest_complex (arg_float_complex, arg_double_complex) & |
| 83 |
bind (c) |
| 84 |
use iso_c_binding |
| 85 |
complex(C_FLOAT_COMPLEX), pointer :: arg_float_complex |
| 86 |
complex(C_DOUBLE_COMPLEX), pointer :: arg_double_complex |
| 87 |
end subroutine |
| 88 |
|
| 89 |
subroutine ctest_misc (arg_bool, arg_cptr, arg_cfunptr, arg_struct) & |
| 90 |
bind (c) |
| 91 |
use iso_c_binding |
| 92 |
use mm |
| 93 |
logical(C_BOOL), pointer :: arg_bool |
| 94 |
type(C_PTR), pointer :: arg_cptr |
| 95 |
type(C_FUNPTR), pointer :: arg_cfunptr |
| 96 |
type(s), pointer :: arg_struct |
| 97 |
end subroutine |
| 98 |
|
| 99 |
end interface |
| 100 |
|
| 101 |
integer(C_INT), pointer :: var_int |
| 102 |
integer(C_SHORT), pointer :: var_short |
| 103 |
integer(C_LONG), pointer :: var_long |
| 104 |
integer(C_LONG_LONG), pointer :: var_long_long |
| 105 |
integer(C_SIGNED_CHAR), pointer :: var_signed_char |
| 106 |
integer(C_INT8_T), pointer :: var_int8 |
| 107 |
integer(C_INT16_T), pointer :: var_int16 |
| 108 |
integer(C_INT32_T), pointer :: var_int32 |
| 109 |
integer(C_INT64_T), pointer :: var_int64 |
| 110 |
integer(C_INT_LEAST8_T), pointer :: var_least8 |
| 111 |
integer(C_INT_LEAST16_T), pointer :: var_least16 |
| 112 |
integer(C_INT_LEAST32_T), pointer :: var_least32 |
| 113 |
integer(C_INT_LEAST64_T), pointer :: var_least64 |
| 114 |
integer(C_INT_FAST8_T), pointer :: var_fast8 |
| 115 |
integer(C_INT_FAST16_T), pointer :: var_fast16 |
| 116 |
integer(C_INT_FAST32_T), pointer :: var_fast32 |
| 117 |
integer(C_INT_FAST64_T), pointer :: var_fast64 |
| 118 |
integer(C_SIZE_T), pointer :: var_size |
| 119 |
integer(C_INTMAX_T), pointer :: var_intmax |
| 120 |
integer(C_INTPTR_T), pointer :: var_intptr |
| 121 |
integer(C_PTRDIFF_T), pointer :: var_ptrdiff |
| 122 |
real(C_FLOAT), pointer :: var_float |
| 123 |
real(C_DOUBLE), pointer :: var_double |
| 124 |
complex(C_FLOAT_COMPLEX), pointer :: var_float_complex |
| 125 |
complex(C_DOUBLE_COMPLEX), pointer :: var_double_complex |
| 126 |
logical(C_BOOL), pointer :: var_bool |
| 127 |
type(C_PTR), pointer :: var_cptr |
| 128 |
type(C_FUNPTR), pointer :: var_cfunptr |
| 129 |
type(s), pointer :: var_struct |
| 130 |
|
| 131 |
nullify (var_int, var_short, var_long, var_long_long, var_signed_char) |
| 132 |
call ctest_int1 (var_int, var_short, var_long, var_long_long, & |
| 133 |
var_signed_char) |
| 134 |
|
| 135 |
nullify (var_int8, var_int16, var_int32, var_int64) |
| 136 |
call ctest_int2 (var_int8, var_int16, var_int32, var_int64) |
| 137 |
|
| 138 |
nullify (var_least8, var_least16, var_least32, var_least64) |
| 139 |
call ctest_int3 (var_least8, var_least16, var_least32, var_least64) |
| 140 |
|
| 141 |
nullify (var_fast8, var_fast16, var_fast32, var_fast64) |
| 142 |
call ctest_int4 (var_fast8, var_fast16, var_fast32, var_fast64) |
| 143 |
|
| 144 |
nullify (var_size, var_intmax, var_intptr, var_ptrdiff) |
| 145 |
call ctest_int5 (var_size, var_intmax, var_intptr, var_ptrdiff) |
| 146 |
|
| 147 |
nullify (var_float, var_double) |
| 148 |
call ctest_real (var_float, var_double) |
| 149 |
|
| 150 |
nullify (var_float_complex, var_double_complex) |
| 151 |
call ctest_complex (var_float_complex, var_double_complex) |
| 152 |
|
| 153 |
nullify (var_bool, var_cptr, var_cfunptr, var_struct) |
| 154 |
call ctest_misc (var_bool, var_cptr, var_cfunptr, var_struct) |
| 155 |
|
| 156 |
! FIXME: how do you pass something that corresponds to CFI_type_other? |
| 157 |
! The Fortran front end complains if you try to pass something that |
| 158 |
! isn't interoperable, such as a derived type object without bind(c). |
| 159 |
|
| 160 |
end program |