Commit
fef67987cf502fe322e92ddce22eea7ac46b4d75 changed the
libgfortran build process to generate multilib-specific versions of
ISO_Fortran_binding.h from a template, by running gfortran to identify
the values of the Fortran kind constants C_LONG_DOUBLE, C_FLOAT128,
and C_INT128_T. This caused multiple problems with search paths, both
for build-tree testing and installed-tree use, not all of which have
been fixed.
This patch reverts to a non-multilib-specific .h file that uses GCC's
predefined preprocessor symbols to detect the supported types and map
them to kind values in the same way as the Fortran front end.
2021-09-06 Sandra Loosemore <sandra@codesourcery.com>
libgfortran/
* ISO_Fortran_binding-1-tmpl.h: Deleted.
* ISO_Fortran_binding-2-tmpl.h: Deleted.
* ISO_Fortran_binding-3-tmpl.h: Deleted.
* ISO_Fortran_binding.h: New file to replace the above.
* Makefile.am (gfor_cdir): Remove MULTISUBDIR.
(ISO_Fortran_binding.h): Simplify to just copy the file.
* Makefile.in: Regenerated.
* mk-kinds-h.sh: Revert pieces no longer needed for
ISO_Fortran_binding.h.
+++ /dev/null
-#include "config.h"
-#include "kinds.inc"
-
-/* Note that -1 is used by CFI_type_other, hence, -2 is used for unavailable kinds. */
-
-#if GFC_C_INT128_T_KIND == 16
-#define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
-#define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
-#define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
-#elif GFC_C_INT128_T_KIND < 0
-#define CFI_type_int128_t -2
-#define CFI_type_int_least128_t -2
-#define CFI_type_int_fast128_t -2
-#else
-#error "Unexpected value for GFC_C_INT128_T_KIND"
-#endif
-
-#if GFC_C_LONG_DOUBLE_KIND == 16
-#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
-#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
-#elif GFC_C_LONG_DOUBLE_KIND == 10
-#define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift))
-#define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift))
-#elif GFC_C_LONG_DOUBLE_KIND == 8
-#define CFI_type_long_double (CFI_type_Real + (8 << CFI_type_kind_shift))
-#define CFI_type_long_double_Complex (CFI_type_Complex + (8 << CFI_type_kind_shift))
-#elif GFC_C_LONG_DOUBLE_KIND < 0
-#define CFI_type_long_double -2
-#define CFI_type_long_double_Complex -2
-#else
-#error "Unexpected value for GFC_C_LONG_DOUBLE_KIND"
-#endif
-
-#if GFC_C_FLOAT128_KIND == 16
-#define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift))
-#define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
-#elif GFC_C_FLOAT128_KIND < 0
-#define CFI_type_float128 -2
-#define CFI_type_float128_Complex -2
-#else
-#error "Unexpected value for GFC_C_FLOAT128_KIND"
-#endif
+++ /dev/null
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ISO_FORTRAN_BINDING_H */
#include <stddef.h> /* Standard ptrdiff_t tand size_t. */
#include <stdint.h> /* Integer types. */
+#include <float.h> /* Macros for floating-point type characteristics. */
/* Constants, defined as macros. */
#define CFI_VERSION 1
#define CFI_type_double (CFI_type_Real + (sizeof (double) << CFI_type_kind_shift))
#define CFI_type_float_Complex (CFI_type_Complex + (sizeof (float) << CFI_type_kind_shift))
#define CFI_type_double_Complex (CFI_type_Complex + (sizeof (double) << CFI_type_kind_shift))
+
+/* If GCC supports int128_t on this target, it predefines
+ __SIZEOF_INT128__ to 16. */
+#if defined(__SIZEOF_INT128__)
+#if (__SIZEOF_INT128__ == 16)
+#define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
+#define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
+#define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
+#else
+#error "Can't determine kind of int128_t"
+#endif
+#else
+#define CFI_type_int128_t -2
+#define CFI_type_int_least128_t -2
+#define CFI_type_int_fast128_t -2
+#endif
+
+/* The situation with long double support is more complicated; we need to
+ examine the type in more detail to figure out its kind. */
+
+/* Long double is the same kind as double. */
+#if (LDBL_MANT_DIG == DBL_MANT_DIG \
+ && LDBL_MIN_EXP == DBL_MIN_EXP \
+ && LDBL_MAX_EXP == DBL_MAX_EXP)
+#define CFI_type_long_double CFI_type_double
+#define CFI_type_long_double_Complex CFI_type_double_Complex
+
+/* This is the 80-bit encoding on x86; Fortran assigns it kind 10. */
+#elif (LDBL_MANT_DIG == 64 \
+ && LDBL_MIN_EXP == -16381 \
+ && LDBL_MAX_EXP == 16384)
+#define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift))
+#define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift))
+
+/* This is the IEEE 128-bit encoding, same as float128. */
+#elif (LDBL_MANT_DIG == 113 \
+ && LDBL_MIN_EXP == -16381 \
+ && LDBL_MAX_EXP == 16384)
+#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
+#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
+
+/* This is the IBM128 encoding used on PowerPC; also assigned kind 16. */
+#elif (LDBL_MANT_DIG == 106 \
+ && LDBL_MIN_EXP == -968 \
+ && LDBL_MAX_EXP == 1024)
+#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
+#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
+#define CFI_no_float128 1
+
+/* It's a bug if we get here. If you've got a target that has some other
+ long double encoding, you need add something here for Fortran to
+ recognize it. */
+#else
+#error "Can't determine kind of long double"
+#endif
+
+/* Similarly for __float128. This always refers to the IEEE encoding
+ and not some other 128-bit representation, so if we already used
+ kind 16 for a non-IEEE representation, this one must be unsupported
+ in Fortran even if it's available in C. */
+#if (!defined (CFI_no_float128) \
+ && defined(__FLT128_MANT_DIG__) && __FLT128_MANT_DIG__ == 113 \
+ && defined(__FLT128_MIN_EXP__) && __FLT128_MIN_EXP__ == -16381 \
+ && defined(__FLT128_MAX_EXP__) && __FLT128_MAX_EXP__ == 16384)
+#define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift))
+#define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
+#else
+#define CFI_type_float128 -2
+#define CFI_type_float128_Complex -2
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ISO_FORTRAN_BINDING_H */
endif
gfor_c_HEADERS = ISO_Fortran_binding.h
-gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
+gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \
$(lt_host_flags)
# Place ISO_Fortran_binding.h also under include/ in the build directory such
# that it can be used for in-built-tree testsuite runs without interference of
# other files in the build dir - like intrinsic .mod files or other .h files.
-ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding-1-tmpl.h \
- $(srcdir)/ISO_Fortran_binding-2-tmpl.h \
- $(srcdir)/ISO_Fortran_binding-3-tmpl.h \
- kinds.inc
+ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding.h
-rm -f $@
- cp $(srcdir)/ISO_Fortran_binding-1-tmpl.h $@
- $(COMPILE) -E -dD $(srcdir)/ISO_Fortran_binding-2-tmpl.h \
- | grep '^#define CFI_type' >> $@
- cat $(srcdir)/ISO_Fortran_binding-3-tmpl.h >> $@
+ cp $(srcdir)/ISO_Fortran_binding.h $@
$(MKDIR_P) include
-rm -f include/ISO_Fortran_binding.h
cp $@ include/ISO_Fortran_binding.h
@LIBGFOR_USE_SYMVER_GNU_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = $(srcdir)/gfortran.map
@LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.map-sun
gfor_c_HEADERS = ISO_Fortran_binding.h
-gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
+gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \
$(lt_host_flags)
# Place ISO_Fortran_binding.h also under include/ in the build directory such
# that it can be used for in-built-tree testsuite runs without interference of
# other files in the build dir - like intrinsic .mod files or other .h files.
-ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding-1-tmpl.h \
- $(srcdir)/ISO_Fortran_binding-2-tmpl.h \
- $(srcdir)/ISO_Fortran_binding-3-tmpl.h \
- kinds.inc
+ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding.h
-rm -f $@
- cp $(srcdir)/ISO_Fortran_binding-1-tmpl.h $@
- $(COMPILE) -E -dD $(srcdir)/ISO_Fortran_binding-2-tmpl.h \
- | grep '^#define CFI_type' >> $@
- cat $(srcdir)/ISO_Fortran_binding-3-tmpl.h >> $@
+ cp $(srcdir)/ISO_Fortran_binding.h $@
$(MKDIR_P) include
-rm -f include/ISO_Fortran_binding.h
cp $@ include/ISO_Fortran_binding.h
echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};"
echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};"
echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};"
- echo "#define HAVE_GFC_LOGICAL_${k} 1"
- echo "#define HAVE_GFC_INTEGER_${k} 1"
+ echo "#define HAVE_GFC_LOGICAL_${k}"
+ echo "#define HAVE_GFC_INTEGER_${k}"
echo ""
fi
rm -f tmp$$.*
# Output the information we've gathered
echo "typedef ${ctype} GFC_REAL_${k};"
echo "typedef ${cplxtype} GFC_COMPLEX_${k};"
- echo "#define HAVE_GFC_REAL_${k} 1"
- echo "#define HAVE_GFC_COMPLEX_${k} 1"
+ echo "#define HAVE_GFC_REAL_${k}"
+ echo "#define HAVE_GFC_COMPLEX_${k}"
echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}"
echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}"
if [ "x$suffix" = "x" ]; then
rm -f tmp$$.*
done
-# For ISO_Fortran_binding.h
-for k in "C_LONG_DOUBLE" "C_FLOAT128" "C_INT128_T"; do
- fname="tmp$$.val"
- echo "use iso_c_binding, only: $k; end" > tmp$$.f90
- if $compile -S -fdump-parse-tree tmp$$.f90 > "$fname"; then
- kind=`grep "value:" "$fname" |grep value: | sed -e 's/.*value: *//'`
- if [ "x$kind" = "x" ]; then
- echo "ERROR: Failed to extract kind for $k" 1>&2
- exit 1
- fi
- echo "#define GFC_${k}_KIND ${kind}"
- else
- echo "ERROR: Failed to extract kind for $k" 1>&2
- exit 1
- fi
- rm -f tmp$$.*
-done
# After this, we include a header that can override some of the
# autodetected settings.