This set of patches is for PR libfortran/101305, about bugs in ISO_Fortran_binding.h's type kind/size encodings, and also incorrect kind/size mappings in CFI_establish. For instance, ISO_Fortran_binding.h had hard-wired encodings that ptrdiff_t and long are 8 bytes that are clearly incorrect on a 32-bit target, and other encodings like CFI_type_int_fast8_t and CFI_type_long_double were incorrect on some 64-bit targets too. So part of this patch involves using sizeof in the CFI_type_* macro definitions, instead of literal constants.
Another difficulty is that the 2018 Fortran standard requires that the CFI_type_* macros for C types not supported by the Fortran processor have negative values. Tobias contributed some scripting to check for that; now ISO_Fortran_binding.h is generated at build time from fragments in the libgfortran source directory. The remaining parts of the patch fix up related bugs in CFI_establish for types whose size isn't directly encoded in the corresponding CFI_type_* macro, and adjust include paths for ISO_Fortran_binding.h in the test suite. Jose has posted a patch that fixes some additional bugs in type/size encodings in descriptors passed to and from C: https://gcc.gnu.org/pipermail/fortran/2021-June/056154.html and there remains a messy bug (PR fortran/100917) relating to ambiguity in handling long double on some targets -- specifically, on x86_64 targets that have both 80-bit long doubles with a storage size of 16 and a true 128-bit floating-point format, the GFC descriptor representation can't tell them apart. I tested these patches on i686-pc-linux-gnu with both -m32 and -m64 multilibs. Sandra Loosemore (3): [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c | 2 +- gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c | 2 +- .../gfortran.dg/bind_c_array_params_3_aux.c | 2 +- .../iso_fortran_binding_uint8_array_driver.c | 2 +- gcc/testsuite/gfortran.dg/pr93524.c | 2 +- libgfortran/ISO_Fortran_binding-1-tmpl.h | 196 ++++++++++++++++++++ libgfortran/ISO_Fortran_binding-2-tmpl.h | 42 +++++ libgfortran/ISO_Fortran_binding-3-tmpl.h | 5 + libgfortran/ISO_Fortran_binding.h | 206 --------------------- libgfortran/Makefile.am | 15 +- libgfortran/Makefile.in | 16 +- libgfortran/mk-kinds-h.sh | 25 ++- libgfortran/runtime/ISO_Fortran_binding.c | 21 ++- 25 files changed, 319 insertions(+), 241 deletions(-) create mode 100644 libgfortran/ISO_Fortran_binding-1-tmpl.h create mode 100644 libgfortran/ISO_Fortran_binding-2-tmpl.h create mode 100644 libgfortran/ISO_Fortran_binding-3-tmpl.h delete mode 100644 libgfortran/ISO_Fortran_binding.h -- 2.8.1