Fortran: Revert to non-multilib-specific ISO_Fortran_binding.h

Commit fef67987cf 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.
This commit is contained in:
Sandra Loosemore 2021-09-06 21:25:11 -07:00
parent 546ecb0054
commit 13beaf9e8d
6 changed files with 87 additions and 86 deletions

View File

@ -1,42 +0,0 @@
#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

View File

@ -1,5 +0,0 @@
#ifdef __cplusplus
}
#endif
#endif /* ISO_FORTRAN_BINDING_H */

View File

@ -32,6 +32,7 @@ extern "C" {
#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
@ -198,3 +199,79 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
#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 */

View File

@ -31,7 +31,7 @@ version_dep =
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)
@ -1079,15 +1079,9 @@ fpu-target.inc: fpu-target.h $(srcdir)/libgfortran.h
# 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

View File

@ -725,7 +725,7 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
@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)
@ -7045,15 +7045,9 @@ fpu-target.inc: fpu-target.h $(srcdir)/libgfortran.h
# 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

View File

@ -35,8 +35,8 @@ for k in $possible_integer_kinds; do
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$$.*
@ -98,8 +98,8 @@ for k in $possible_real_kinds; do
# 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
@ -114,23 +114,6 @@ for k in $possible_real_kinds; do
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.