2 ! { dg-additional-sources PR100915.c }
4 ! Test the fix for PR100915
9 use, intrinsic :: iso_c_binding
, only
: &
10 c_signed_char
, c_int16_t
17 CFI_type_cptr
, CFI_type_cfunptr
29 integer, parameter :: CFI_type_t
= c_int16_t
31 integer(kind
=c_int16_t
), parameter :: CFI_type_mask
= int(z
"FF", kind
=c_int16_t
)
32 integer(kind
=c_int16_t
), parameter :: CFI_type_kind_shift
= 8_c_int16_t
34 ! Intrinsic types. Their kind number defines their storage size. */
35 integer(kind
=c_signed_char
), parameter :: CFI_type_cptr
= 7
36 integer(kind
=c_signed_char
), parameter :: CFI_type_cfunptr
= 8
39 subroutine check_fn_as(a
, t
, k
, e
, n
) &
40 bind(c
, name
="check_fn")
41 use, intrinsic :: iso_c_binding
, only
: &
42 c_int16_t
, c_signed_char
, c_size_t
44 type(*), intent(in
) :: a(:)
45 integer(c_int16_t
), value
, intent(in
) :: t
46 integer(c_signed_char
), value
, intent(in
) :: k
47 integer(c_size_t
), value
, intent(in
) :: e
48 integer(c_size_t
), value
, intent(in
) :: n
49 end subroutine check_fn_as
50 subroutine check_fn_ar(a
, t
, k
, e
, n
) &
51 bind(c
, name
="check_fn")
52 use, intrinsic :: iso_c_binding
, only
: &
53 c_int16_t
, c_signed_char
, c_size_t
55 type(*), intent(in
) :: a(..)
56 integer(c_int16_t
), value
, intent(in
) :: t
57 integer(c_signed_char
), value
, intent(in
) :: k
58 integer(c_size_t
), value
, intent(in
) :: e
59 integer(c_size_t
), value
, intent(in
) :: n
60 end subroutine check_fn_ar
65 function mult2(a
) result(b
) bind(c
)
66 use, intrinsic :: iso_c_binding
, only
: &
69 integer(kind
=c_int
), value
, intent(in
) :: a
71 integer(kind
=c_int
) :: b
77 elemental
function cfi_encode_type(type, kind
) result(itype
)
78 integer(kind
=c_signed_char
), intent(in
) :: type
79 integer(kind
=c_signed_char
), intent(in
) :: kind
81 integer(kind
=c_int16_t
) :: itype
, ikind
83 itype
= int(type, kind
=c_int16_t
)
84 itype
= iand(itype
, CFI_type_mask
)
85 ikind
= int(kind
, kind
=c_int16_t
)
86 ikind
= iand(ikind
, CFI_type_mask
)
87 ikind
= shiftl(ikind
, CFI_type_kind_shift
)
88 itype
= ior(ikind
, itype
)
90 end function cfi_encode_type
96 use, intrinsic :: iso_c_binding
, only
: &
97 c_signed_char
, c_int16_t
, c_size_t
99 use, intrinsic :: iso_c_binding
, only
: &
100 c_funptr
, c_funloc
, c_associated
102 use :: isof_m
, only
: &
103 CFI_type_cptr
, CFI_type_cfunptr
105 use :: isof_m
, only
: &
109 use :: isof_m
, only
: &
112 use :: isof_m
, only
: &
118 integer(kind
=c_size_t
), parameter :: b
= 8
119 integer, parameter :: n
= 11
123 subroutine check_c_funptr()
124 type(c_funptr
) :: p(n
)
127 p
= [(c_funloc(mult2
), i
=1,n
)]
128 call f_check_c_funptr_as(p
)
130 if(.not
.c_associated(p(i
), c_funloc(mult2
))) stop 1
132 p
= [(c_funloc(mult2
), i
=1,n
)]
133 call c_check_c_funptr_as(p
)
135 if(.not
.c_associated(p(i
), c_funloc(mult2
))) stop 2
137 p
= [(c_funloc(mult2
), i
=1,n
)]
138 call f_check_c_funptr_ar(p
)
140 if(.not
.c_associated(p(i
), c_funloc(mult2
))) stop 3
142 p
= [(c_funloc(mult2
), i
=1,n
)]
143 call c_check_c_funptr_ar(p
)
145 if(.not
.c_associated(p(i
), c_funloc(mult2
))) stop 4
148 end subroutine check_c_funptr
150 subroutine f_check_c_funptr_as(a
)
151 type(c_funptr
), intent(in
) :: a(:)
153 integer(kind
=c_int16_t
) :: t
154 integer(kind
=c_signed_char
) :: k
155 integer(kind
=c_size_t
) :: e
158 e
= storage_size(a
)/b
159 t
= cfi_encode_type(CFI_type_cfunptr
, k
)
160 ! Assumes 64-bit target.
163 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 6
165 call check_fn_as(a
, t
, k
, e
, 1_c_size_t
)
167 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 7
170 end subroutine f_check_c_funptr_as
172 subroutine c_check_c_funptr_as(a
) bind(c
)
173 type(c_funptr
), intent(in
) :: a(:)
174 integer(kind
=c_int16_t
) :: t
175 integer(kind
=c_signed_char
) :: k
176 integer(kind
=c_size_t
) :: e
179 e
= storage_size(a
)/b
180 t
= cfi_encode_type(CFI_type_cfunptr
, k
)
181 ! Assumes 64-bit target.
184 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 9
186 call check_fn_as(a
, t
, k
, e
, 1_c_size_t
)
188 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 10
191 end subroutine c_check_c_funptr_as
193 subroutine f_check_c_funptr_ar(a
)
194 type(c_funptr
), intent(in
) :: a(..)
196 integer(kind
=c_int16_t
) :: t
197 integer(kind
=c_signed_char
) :: k
198 integer(kind
=c_size_t
) :: e
201 e
= storage_size(a
)/b
202 t
= cfi_encode_type(CFI_type_cfunptr
, k
)
203 ! Assumes 64-bit target.
208 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 12
213 call check_fn_ar(a
, t
, k
, e
, 1_c_size_t
)
217 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 14
223 end subroutine f_check_c_funptr_ar
225 subroutine c_check_c_funptr_ar(a
) bind(c
)
226 type(c_funptr
), intent(in
) :: a(..)
227 integer(kind
=c_int16_t
) :: t
228 integer(kind
=c_signed_char
) :: k
229 integer(kind
=c_size_t
) :: e
232 e
= storage_size(a
)/b
233 t
= cfi_encode_type(CFI_type_cfunptr
, k
)
234 ! Assumes 64-bit target.
239 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 17
244 call check_fn_ar(a
, t
, k
, e
, 1_c_size_t
)
248 if(.not
.c_associated(a(i
), c_funloc(mult2
))) stop 19
254 end subroutine c_check_c_funptr_ar
256 end module iso_check_m
260 use :: iso_check_m
, only
: &
265 call check_c_funptr()