Debian Codegraph @

gcc/testsuite/gfortran.dg/c-interop/typecodes-array-basic.f90

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