| 1 |
#include <stdlib.h> |
| 2 |
#include <stdint.h> |
| 3 |
#include <stdio.h> |
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
#include <ISO_Fortran_binding.h> |
| 7 |
|
| 8 |
extern void ctest_typecodes (void); |
| 9 |
|
| 10 |
/* Do sanity checking on the CFI_type_* macros. In particular, make sure |
| 11 |
that if two type codes have the same value, they represent objects of the |
| 12 |
same size. */ |
| 13 |
|
| 14 |
struct tc_info |
| 15 |
{ |
| 16 |
CFI_type_t typecode; |
| 17 |
char *name; |
| 18 |
size_t size; |
| 19 |
int extension; |
| 20 |
}; |
| 21 |
|
| 22 |
static struct tc_info tc_table[] = |
| 23 |
{ |
| 24 |
/* Extension types. |
| 25 |
Note there is no portable C equivalent type for CFI_type_ucs4_char type |
| 26 |
(4-byte Unicode characters), so this is kind of hacky... */ |
| 27 |
#if CFI_type_int128_t > 0 |
| 28 |
{ CFI_type_int128_t, "CFI_type_int128_t", |
| 29 |
sizeof (__int128), 1 }, |
| 30 |
{ CFI_type_int_least128_t, "CFI_type_int_least128_t", |
| 31 |
sizeof (__int128), 1 }, |
| 32 |
{ CFI_type_int_fast128_t, "CFI_type_int_fast128_t", |
| 33 |
sizeof (__int128), 1 }, |
| 34 |
#endif |
| 35 |
#if CFI_type_ucs4_char > 0 |
| 36 |
{ CFI_type_ucs4_char, "CFI_type_ucs4_char", 4, 1 }, |
| 37 |
#endif |
| 38 |
#if CFI_type_float128 > 0 |
| 39 |
{ CFI_type_float128, "CFI_type_float128", |
| 40 |
sizeof (_Float128), 1 }, |
| 41 |
{ CFI_type_float128_Complex, "CFI_type_float128_Complex", |
| 42 |
sizeof (_Float128 _Complex), 1 }, |
| 43 |
#endif |
| 44 |
#if CFI_type_cfunptr > 0 |
| 45 |
{ CFI_type_cfunptr, "CFI_type_cfunptr", |
| 46 |
sizeof (void (*)(void)), 1 }, |
| 47 |
#endif |
| 48 |
|
| 49 |
/* Standard types. */ |
| 50 |
{ CFI_type_signed_char, "CFI_type_signed_char", |
| 51 |
sizeof (signed char), 0, }, |
| 52 |
{ CFI_type_short, "CFI_type_short", |
| 53 |
sizeof (short), 0 }, |
| 54 |
{ CFI_type_int, "CFI_type_int", |
| 55 |
sizeof (int), 0 }, |
| 56 |
{ CFI_type_long, "CFI_type_long", |
| 57 |
sizeof (long), 0 }, |
| 58 |
{ CFI_type_long_long, "CFI_type_long_long", |
| 59 |
sizeof (long long), 0 }, |
| 60 |
{ CFI_type_size_t, "CFI_type_size_t", |
| 61 |
sizeof (size_t), 0 }, |
| 62 |
{ CFI_type_int8_t, "CFI_type_int8_t", |
| 63 |
sizeof (int8_t), 0 }, |
| 64 |
{ CFI_type_int16_t, "CFI_type_int16_t", |
| 65 |
sizeof (int16_t), 0 }, |
| 66 |
{ CFI_type_int32_t, "CFI_type_int32_t", |
| 67 |
sizeof (int32_t), 0 }, |
| 68 |
{ CFI_type_int64_t, "CFI_type_int64_t", |
| 69 |
sizeof (int64_t), 0 }, |
| 70 |
{ CFI_type_int_least8_t, "CFI_type_int_least8_t", |
| 71 |
sizeof (int_least8_t), 0 }, |
| 72 |
{ CFI_type_int_least16_t, "CFI_type_int_least16_t", |
| 73 |
sizeof (int_least16_t), 0 }, |
| 74 |
{ CFI_type_int_least32_t, "CFI_type_int_least32_t", |
| 75 |
sizeof (int_least32_t), 0 }, |
| 76 |
{ CFI_type_int_least64_t, "CFI_type_int_least64_t", |
| 77 |
sizeof (int_least64_t), 0 }, |
| 78 |
{ CFI_type_int_fast8_t, "CFI_type_int_fast8_t", |
| 79 |
sizeof (int_fast8_t), 0 }, |
| 80 |
{ CFI_type_int_fast16_t, "CFI_type_int_fast16_t", |
| 81 |
sizeof (int_fast16_t), 0 }, |
| 82 |
{ CFI_type_int_fast32_t, "CFI_type_int_fast32_t", |
| 83 |
sizeof (int_fast32_t), 0 }, |
| 84 |
{ CFI_type_int_fast64_t, "CFI_type_int_fast64_t", |
| 85 |
sizeof (int_fast64_t), 0 }, |
| 86 |
{ CFI_type_intmax_t, "CFI_type_intmax_t", |
| 87 |
sizeof (intmax_t), 0 }, |
| 88 |
{ CFI_type_intptr_t, "CFI_type_intptr_t", |
| 89 |
sizeof (intptr_t), 0 }, |
| 90 |
{ CFI_type_ptrdiff_t, "CFI_type_ptrdiff_t", |
| 91 |
sizeof (ptrdiff_t), 0 }, |
| 92 |
{ CFI_type_float, "CFI_type_float", |
| 93 |
sizeof (float), 0 }, |
| 94 |
{ CFI_type_double, "CFI_type_double", |
| 95 |
sizeof (double), 0 }, |
| 96 |
{ CFI_type_long_double, "CFI_type_long_double", |
| 97 |
sizeof (long double), 0 }, |
| 98 |
{ CFI_type_float_Complex, "CFI_type_float_Complex", |
| 99 |
sizeof (float _Complex), 0 }, |
| 100 |
{ CFI_type_double_Complex, "CFI_type_double_Complex", |
| 101 |
sizeof (double _Complex), 0 }, |
| 102 |
{ CFI_type_long_double_Complex, "CFI_type_long_double_Complex", |
| 103 |
sizeof (long double _Complex), 0 }, |
| 104 |
{ CFI_type_Bool, "CFI_type_Bool", |
| 105 |
sizeof (_Bool), 0 }, |
| 106 |
{ CFI_type_char, "CFI_type_char", |
| 107 |
sizeof (char), 0 }, |
| 108 |
{ CFI_type_cptr, "CFI_type_cptr", |
| 109 |
sizeof (void *), 0 }, |
| 110 |
{ CFI_type_struct, "CFI_type_struct", 0, 0 }, |
| 111 |
{ CFI_type_other, "CFI_type_other", -1, 0, } |
| 112 |
}; |
| 113 |
|
| 114 |
void |
| 115 |
ctest_typecodes (void) |
| 116 |
{ |
| 117 |
int ncodes = sizeof (tc_table) / sizeof (struct tc_info); |
| 118 |
int i, j; |
| 119 |
int bad = 0; |
| 120 |
|
| 121 |
for (i = 0; i < ncodes; i++) |
| 122 |
for (j = i + 1; j < ncodes; j++) |
| 123 |
if (tc_table[i].typecode == tc_table[j].typecode |
| 124 |
&& tc_table[i].typecode > 0 |
| 125 |
&& (tc_table[i].size != tc_table[j].size)) |
| 126 |
{ |
| 127 |
fprintf (stderr, |
| 128 |
"type codes have the same value %d but different sizes\n", |
| 129 |
(int) tc_table[i].typecode); |
| 130 |
fprintf (stderr, " %s size %d\n", |
| 131 |
tc_table[i].name, (int) tc_table[i].size); |
| 132 |
fprintf (stderr, " %s size %d\n", |
| 133 |
tc_table[j].name, (int) tc_table[j].size); |
| 134 |
bad = 1; |
| 135 |
} |
| 136 |
|
| 137 |
/* TS29113 Section 8.3.4: The value for CFI_type_other shall be negative |
| 138 |
and distinct from all other type specifiers. If a C type is not |
| 139 |
interoperable with a Fortran type and kind supported by the |
| 140 |
Fortran processor, its macro shall evaluate to a negative value. |
| 141 |
Otherwise, the value for an intrinsic type shall be positive. |
| 142 |
|
| 143 |
In the case of GCC, we expect that all the standard intrinsic |
| 144 |
types are supported by both Fortran and C, so they should all be |
| 145 |
positive except for CFI_type_other. Non-standard ones may have a |
| 146 |
value -2. */ |
| 147 |
|
| 148 |
for (i = 0; i < ncodes; i++) |
| 149 |
{ |
| 150 |
if (tc_table[i].typecode == CFI_type_other) |
| 151 |
{ |
| 152 |
if (tc_table[i].typecode >= 0) |
| 153 |
{ |
| 154 |
fprintf (stderr, "%s value %d is not negative\n", |
| 155 |
tc_table[i].name, (int)tc_table[i].typecode); |
| 156 |
bad = 1; |
| 157 |
} |
| 158 |
if (strcmp (tc_table[i].name, "CFI_type_other")) |
| 159 |
{ |
| 160 |
fprintf (stderr, "%s has the same value %d as CFI_type_other\n", |
| 161 |
tc_table[i].name, (int)CFI_type_other); |
| 162 |
bad = 1; |
| 163 |
} |
| 164 |
} |
| 165 |
else if (tc_table[i].typecode == -2 && tc_table[i].extension) |
| 166 |
/* Unsupported extension type on this target; this is OK */ |
| 167 |
; |
| 168 |
else if (tc_table[i].typecode <= 0) |
| 169 |
{ |
| 170 |
fprintf (stderr, "%s value %d is not positive\n", |
| 171 |
tc_table[i].name, (int)tc_table[i].typecode); |
| 172 |
bad = 1; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
if (bad) |
| 177 |
abort (); |
| 178 |
} |