1 #include <stdlib.h>
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <string.h>
5 
6 #include <ISO_Fortran_binding.h>
7 #include "dump-descriptors.h"
8 
9 extern void ctest_int1 (CFI_cdesc_t *arg_int,
10 			CFI_cdesc_t *arg_short,
11 			CFI_cdesc_t *arg_long,
12 			CFI_cdesc_t *arg_long_long,
13 			CFI_cdesc_t *arg_signed_char);
14 
15 extern void ctest_int2 (CFI_cdesc_t *arg_int8,
16 			CFI_cdesc_t *arg_int16,
17 			CFI_cdesc_t *arg_int32,
18 			CFI_cdesc_t *arg_int64);
19 
20 extern void ctest_int3 (CFI_cdesc_t *arg_least8,
21 			CFI_cdesc_t *arg_least16,
22 			CFI_cdesc_t *arg_least32,
23 			CFI_cdesc_t *arg_least64);
24 
25 extern void ctest_int4 (CFI_cdesc_t *arg_fast8,
26 			CFI_cdesc_t *arg_fast16,
27 			CFI_cdesc_t *arg_fast32,
28 			CFI_cdesc_t *arg_fast64);
29 
30 extern void ctest_int5 (CFI_cdesc_t *arg_size,
31 			CFI_cdesc_t *arg_intmax,
32 			CFI_cdesc_t *arg_intptr,
33 			CFI_cdesc_t *arg_ptrdiff);
34 
35 extern void ctest_real (CFI_cdesc_t *arg_float,
36 			CFI_cdesc_t *arg_double);
37 
38 extern void ctest_complex (CFI_cdesc_t *arg_float_complex,
39 			   CFI_cdesc_t *arg_double_complex);
40 
41 extern void ctest_misc (CFI_cdesc_t *arg_bool,
42 			CFI_cdesc_t *arg_cptr,
43 			CFI_cdesc_t *arg_cfunptr,
44 			CFI_cdesc_t *arg_struct);
45 
46 /* Sanity check the type info in the descriptor a.  */
47 
48 static void
check(CFI_cdesc_t * a,size_t size,int typecode)49 check (CFI_cdesc_t *a, size_t size, int typecode)
50 {
51   dump_CFI_cdesc_t (a);
52   if (a->attribute != CFI_attribute_other)
53     abort ();
54   if (a->base_addr == NULL)
55     abort ();
56   if (a->rank != 1)
57     abort ();
58   if (size && a->elem_len != size)
59     abort ();
60   if (a->type != typecode)
61     abort ();
62 }
63 
64 
65 /* Test that the basic integer types correspond correctly.  */
66 void
ctest_int1(CFI_cdesc_t * arg_int,CFI_cdesc_t * arg_short,CFI_cdesc_t * arg_long,CFI_cdesc_t * arg_long_long,CFI_cdesc_t * arg_signed_char)67 ctest_int1 (CFI_cdesc_t *arg_int,
68 	    CFI_cdesc_t *arg_short,
69 	    CFI_cdesc_t *arg_long,
70 	    CFI_cdesc_t *arg_long_long,
71 	    CFI_cdesc_t *arg_signed_char)
72 {
73   check (arg_int, sizeof (int), CFI_type_int);
74   check (arg_short, sizeof (short), CFI_type_short);
75   check (arg_long, sizeof (long), CFI_type_long);
76   check (arg_long_long, sizeof (long long int), CFI_type_long_long);
77   check (arg_signed_char, sizeof (signed char), CFI_type_signed_char);
78 }
79 
80 /* Test the integer types of explicit sizes.  */
81 void
ctest_int2(CFI_cdesc_t * arg_int8,CFI_cdesc_t * arg_int16,CFI_cdesc_t * arg_int32,CFI_cdesc_t * arg_int64)82 ctest_int2 (CFI_cdesc_t *arg_int8,
83 	    CFI_cdesc_t *arg_int16,
84 	    CFI_cdesc_t *arg_int32,
85 	    CFI_cdesc_t *arg_int64)
86 {
87   check (arg_int8, sizeof (int8_t), CFI_type_int8_t);
88   check (arg_int16, sizeof (int16_t), CFI_type_int16_t);
89   check (arg_int32, sizeof (int32_t), CFI_type_int32_t);
90   check (arg_int64, sizeof (int64_t), CFI_type_int64_t);
91 }
92 
93 /* Check the int_least*_t types.  */
94 
95 void
ctest_int3(CFI_cdesc_t * arg_least8,CFI_cdesc_t * arg_least16,CFI_cdesc_t * arg_least32,CFI_cdesc_t * arg_least64)96 ctest_int3 (CFI_cdesc_t *arg_least8,
97 	    CFI_cdesc_t *arg_least16,
98 	    CFI_cdesc_t *arg_least32,
99 	    CFI_cdesc_t *arg_least64)
100 {
101   check (arg_least8, sizeof (int_least8_t), CFI_type_int_least8_t);
102   check (arg_least16, sizeof (int_least16_t), CFI_type_int_least16_t);
103   check (arg_least32, sizeof (int_least32_t), CFI_type_int_least32_t);
104   check (arg_least64, sizeof (int_least64_t), CFI_type_int_least64_t);
105 }
106 
107 /* Check the int_fast*_t types.  */
108 void
ctest_int4(CFI_cdesc_t * arg_fast8,CFI_cdesc_t * arg_fast16,CFI_cdesc_t * arg_fast32,CFI_cdesc_t * arg_fast64)109 ctest_int4 (CFI_cdesc_t *arg_fast8,
110 	    CFI_cdesc_t *arg_fast16,
111 	    CFI_cdesc_t *arg_fast32,
112 	    CFI_cdesc_t *arg_fast64)
113 {
114   check (arg_fast8, sizeof (int_fast8_t), CFI_type_int_fast8_t);
115   check (arg_fast16, sizeof (int_fast16_t), CFI_type_int_fast16_t);
116   check (arg_fast32, sizeof (int_fast32_t), CFI_type_int_fast32_t);
117   check (arg_fast64, sizeof (int_fast64_t), CFI_type_int_fast64_t);
118 }
119 
120 /* Check the "purposeful" integer types.  */
121 void
ctest_int5(CFI_cdesc_t * arg_size,CFI_cdesc_t * arg_intmax,CFI_cdesc_t * arg_intptr,CFI_cdesc_t * arg_ptrdiff)122 ctest_int5 (CFI_cdesc_t *arg_size,
123 	    CFI_cdesc_t *arg_intmax,
124 	    CFI_cdesc_t *arg_intptr,
125 	    CFI_cdesc_t *arg_ptrdiff)
126 {
127   check (arg_size, sizeof (size_t), CFI_type_size_t);
128   check (arg_intmax, sizeof (intmax_t), CFI_type_intmax_t);
129   check (arg_intptr, sizeof (intptr_t), CFI_type_intptr_t);
130   check (arg_ptrdiff, sizeof (ptrdiff_t), CFI_type_ptrdiff_t);
131 }
132 
133 /* Check the floating-point types.  */
134 void
ctest_real(CFI_cdesc_t * arg_float,CFI_cdesc_t * arg_double)135 ctest_real (CFI_cdesc_t *arg_float,
136 	    CFI_cdesc_t *arg_double)
137 {
138   check (arg_float, sizeof (float), CFI_type_float);
139   check (arg_double, sizeof (double), CFI_type_double);
140 }
141 
142 /* Likewise for the complex types.  */
143 void
ctest_complex(CFI_cdesc_t * arg_float_complex,CFI_cdesc_t * arg_double_complex)144 ctest_complex (CFI_cdesc_t *arg_float_complex,
145 	       CFI_cdesc_t *arg_double_complex)
146 {
147   check (arg_float_complex, sizeof (float _Complex),
148 	 CFI_type_float_Complex);
149   check (arg_double_complex, sizeof (double _Complex),
150 	 CFI_type_double_Complex);
151 }
152 
153 /* Misc types.  */
154 void
ctest_misc(CFI_cdesc_t * arg_bool,CFI_cdesc_t * arg_cptr,CFI_cdesc_t * arg_cfunptr,CFI_cdesc_t * arg_struct)155 ctest_misc (CFI_cdesc_t *arg_bool,
156 	    CFI_cdesc_t *arg_cptr,
157 	    CFI_cdesc_t *arg_cfunptr,
158 	    CFI_cdesc_t *arg_struct)
159 {
160   struct m
161   {
162     int i, j;
163   };
164 
165   check (arg_bool, sizeof (_Bool), CFI_type_Bool);
166   check (arg_cptr, sizeof (void *), CFI_type_cptr);
167   check (arg_cfunptr, sizeof (void (*)(void)), CFI_type_cfunptr);
168   check (arg_struct, sizeof (struct m), CFI_type_struct);
169 }
170