public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
@ 2021-08-19  2:57 Sandra Loosemore
  2021-09-03  2:05 ` PING " Sandra Loosemore
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Sandra Loosemore @ 2021-08-19  2:57 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Tobias Burnus

[-- Attachment #1: Type: text/plain, Size: 1157 bytes --]

This is a follow-up to commit fef67987cf502fe322e92ddce22eea7ac46b4d75:

https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=fef67987cf502fe322e92ddce22eea7ac46b4d75

I realized last week that having multilib-specific versions of 
ISO_Fortran_binding.h (generated by running the compiler to ask what 
kinds it supports) was still broken outside of the test support; the 
directory where it's being installed isn't on GCC's normal search path. 
It seemed to me that it was better to try to find some other solution 
for this problem than to venture down what appears to be a rat hole.

I've come up with this patch to return to a single ISO_Fortran_binding.h 
file that uses preprocessor magic to identify the Fortran kind 
corresponding to the standard C long double type and the GCC extension 
types __float128 and int128_t.  I haven't attempted to undo the 
follow-up patches that fixed in-tree testing; the static .h file is 
still copied to the build directory, and it can still be referenced with 
<> syntax during testing.

Any complaints about either the overall strategy here, or the logic to 
infer the C type -> kind mapping?  Or OK to commit?

-Sandra

[-- Attachment #2: fix-iso-fortran-binding.h --]
[-- Type: text/x-chdr, Size: 28995 bytes --]

commit bf52fcb46ee62ff2f7c552397d58914b934b130f
Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Fri Aug 13 17:46:19 2021 -0700

    Fortran: Revert to non-multilib-specific ISO_Fortran_binding.h
    
    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-08-18  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.

diff --git a/libgfortran/ISO_Fortran_binding-1-tmpl.h b/libgfortran/ISO_Fortran_binding-1-tmpl.h
deleted file mode 100644
index 8852c99..0000000
--- a/libgfortran/ISO_Fortran_binding-1-tmpl.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/* Declarations for ISO Fortran binding.
-   Copyright (C) 2018-2021 Free Software Foundation, Inc.
-   Contributed by Daniel Celis Garza  <celisdanieljr@gmail.com>
-
-This file is part of the GNU Fortran runtime library (libgfortran).
-
-Libgfortran is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
-
-Libgfortran is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-Under Section 7 of GPL version 3, you are granted additional
-permissions described in the GCC Runtime Library Exception, version
-3.1, as published by the Free Software Foundation.
-
-You should have received a copy of the GNU General Public License and
-a copy of the GCC Runtime Library Exception along with this program;
-see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
-<http://www.gnu.org/licenses/>.  */
-
-#ifndef ISO_FORTRAN_BINDING_H
-#define ISO_FORTRAN_BINDING_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>  /* Standard ptrdiff_t tand size_t. */
-#include <stdint.h>  /* Integer types. */
-
-/* Constants, defined as macros. */
-#define CFI_VERSION 1
-#define CFI_MAX_RANK 15
-
-/* Attributes. */
-#define CFI_attribute_pointer 0
-#define CFI_attribute_allocatable 1
-#define CFI_attribute_other 2
-
-/* Error codes.
-   Note that CFI_FAILURE and CFI_INVALID_STRIDE are specific to GCC
-   and not part of the Fortran standard   */
-#define CFI_SUCCESS 0
-#define CFI_FAILURE 1
-#define CFI_ERROR_BASE_ADDR_NULL 2
-#define CFI_ERROR_BASE_ADDR_NOT_NULL 3
-#define CFI_INVALID_ELEM_LEN 4
-#define CFI_INVALID_RANK 5
-#define CFI_INVALID_TYPE 6
-#define CFI_INVALID_ATTRIBUTE 7
-#define CFI_INVALID_EXTENT 8
-#define CFI_INVALID_STRIDE 9
-#define CFI_INVALID_DESCRIPTOR 10
-#define CFI_ERROR_MEM_ALLOCATION 11
-#define CFI_ERROR_OUT_OF_BOUNDS 12
-
-/* CFI type definitions. */
-typedef ptrdiff_t CFI_index_t;
-typedef int8_t CFI_rank_t;
-typedef int8_t CFI_attribute_t;
-typedef int16_t CFI_type_t;
-
-/* CFI_dim_t. */
-typedef struct CFI_dim_t
-  {
-    CFI_index_t lower_bound;
-    CFI_index_t extent;
-    CFI_index_t sm;
-  }
-CFI_dim_t;
-
-/* CFI_cdesc_t, C descriptors are cast to this structure as follows:
-   CFI_CDESC_T(CFI_MAX_RANK) foo;
-   CFI_cdesc_t * bar = (CFI_cdesc_t *) &foo;
- */
-typedef struct CFI_cdesc_t
- {
-    void *base_addr;
-    size_t elem_len;
-    int version;
-    CFI_rank_t rank;
-    CFI_attribute_t attribute;
-    CFI_type_t type;
-    CFI_dim_t dim[];
- }
-CFI_cdesc_t;
-
-/* CFI_CDESC_T with an explicit type. */
-#define CFI_CDESC_TYPE_T(r, base_type) \
-	struct { \
-		base_type *base_addr; \
-		size_t elem_len; \
-		int version; \
-		CFI_rank_t rank; \
-		CFI_attribute_t attribute; \
-		CFI_type_t type; \
-		CFI_dim_t dim[r]; \
-	}
-#define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void)
-
-/* CFI function declarations. */
-extern void *CFI_address (const CFI_cdesc_t *, const CFI_index_t []);
-extern int CFI_allocate (CFI_cdesc_t *, const CFI_index_t [], const CFI_index_t [],
-			 size_t);
-extern int CFI_deallocate (CFI_cdesc_t *);
-extern int CFI_establish (CFI_cdesc_t *, void *, CFI_attribute_t, CFI_type_t, size_t,
-			  CFI_rank_t, const CFI_index_t []);
-extern int CFI_is_contiguous (const CFI_cdesc_t *);
-extern int CFI_section (CFI_cdesc_t *, const CFI_cdesc_t *, const CFI_index_t [],
-			const CFI_index_t [], const CFI_index_t []);
-extern int CFI_select_part (CFI_cdesc_t *, const CFI_cdesc_t *, size_t, size_t);
-extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
-
-/* Types and kind numbers. Allows bitwise and to reveal the intrinsic type of a kind type. It also allows us to find the kind parameter by inverting the bit-shift equation.
-   CFI_type_kind_shift = 8
-   CFI_intrinsic_type  = 0 0 0 0 0 0 0 0 0 0 1 0
-   CFI_type_kind       = 0 0 0 0 0 0 0 0 1 0 0 0
-   CFI_type_example    = CFI_intrinsic_type + (CFI_type_kind << CFI_type_kind_shift)
-   Defining the CFI_type_example.
-   CFI_type_kind       = 0 0 0 0 0 0 0 0 1 0 0 0  << CFI_type_kind_shift
-			-------------------------
-			 1 0 0 0 0 0 0 0 0 0 0 0  +
-   CFI_intrinsic_type  = 0 0 0 0 0 0 0 0 0 0 1 0
-			-------------------------
-   CFI_type_example    = 1 0 0 0 0 0 0 0 0 0 1 0
-   Finding the intrinsic type with the logical mask.
-   CFI_type_example    = 1 0 0 0 0 0 0 0 0 0 1 0  &
-   CFI_type_mask       = 0 0 0 0 1 1 1 1 1 1 1 1
-			-------------------------
-   CFI_intrinsic_type  = 0 0 0 0 0 0 0 0 0 0 1 0
-   Using the intrinsic type and kind shift to find the kind value of the type.
-   CFI_type_kind = (CFI_type_example - CFI_intrinsic_type) >> CFI_type_kind_shift
-   CFI_type_example   = 1 0 0 0 0 0 0 0 0 0 1 0  -
-   CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
-			-------------------------
-			1 0 0 0 0 0 0 0 0 0 0 0  >> CFI_type_kind_shift
-			-------------------------
-   CFI_type_kind      = 0 0 0 0 0 0 0 0 1 0 0 0
- */
-#define CFI_type_mask 0xFF
-#define CFI_type_kind_shift 8
-
-/* Intrinsic types. Their kind number defines their storage size. */
-#define CFI_type_Integer 1
-#define CFI_type_Logical 2
-#define CFI_type_Real 3
-#define CFI_type_Complex 4
-#define CFI_type_Character 5
-
-/* Types with no kind. */
-#define CFI_type_struct 6
-#define CFI_type_cptr 7
-#define CFI_type_cfunptr 8
-#define CFI_type_other -1
-
-/* Types with kind parameter.
-   The kind parameter represents the type's byte size.  The exception is
-   real kind = 10, which has byte size of 128 bits but 80 bit precision.
-   Complex variables are double the byte size of their real counterparts.
-   The ucs4_char matches wchar_t if sizeof (wchar_t) == 4.
- */
-#define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift))
-#define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift))
-
-/* C-Fortran Interoperability types. */
-#define CFI_type_signed_char (CFI_type_Integer + (sizeof (char) << CFI_type_kind_shift))
-#define CFI_type_short (CFI_type_Integer + (sizeof (short) << CFI_type_kind_shift))
-#define CFI_type_int (CFI_type_Integer + (sizeof (int) << CFI_type_kind_shift))
-#define CFI_type_long (CFI_type_Integer + (sizeof (long) << CFI_type_kind_shift))
-#define CFI_type_long_long (CFI_type_Integer + (sizeof (long long) << CFI_type_kind_shift))
-#define CFI_type_size_t (CFI_type_Integer + (sizeof (size_t) << CFI_type_kind_shift))
-#define CFI_type_int8_t (CFI_type_Integer + (sizeof (int8_t) << CFI_type_kind_shift))
-#define CFI_type_int16_t (CFI_type_Integer + (sizeof (int16_t) << CFI_type_kind_shift))
-#define CFI_type_int32_t (CFI_type_Integer + (sizeof (int32_t) << CFI_type_kind_shift))
-#define CFI_type_int64_t (CFI_type_Integer + (sizeof (int64_t) << CFI_type_kind_shift))
-#define CFI_type_int_least8_t (CFI_type_Integer + (sizeof (int_least8_t) << CFI_type_kind_shift))
-#define CFI_type_int_least16_t (CFI_type_Integer + (sizeof (int_least16_t) << CFI_type_kind_shift))
-#define CFI_type_int_least32_t (CFI_type_Integer + (sizeof (int_least32_t) << CFI_type_kind_shift))
-#define CFI_type_int_least64_t (CFI_type_Integer + (sizeof (int_least64_t) << CFI_type_kind_shift))
-#define CFI_type_int_fast8_t (CFI_type_Integer + (sizeof (int_fast8_t) << CFI_type_kind_shift))
-#define CFI_type_int_fast16_t (CFI_type_Integer + (sizeof (int_fast16_t) << CFI_type_kind_shift))
-#define CFI_type_int_fast32_t (CFI_type_Integer + (sizeof (int_fast32_t) << CFI_type_kind_shift))
-#define CFI_type_int_fast64_t (CFI_type_Integer + (sizeof (int_fast64_t) << CFI_type_kind_shift))
-#define CFI_type_intmax_t (CFI_type_Integer + (sizeof (intmax_t) << CFI_type_kind_shift))
-#define CFI_type_intptr_t (CFI_type_Integer + (sizeof (intptr_t) << CFI_type_kind_shift))
-#define CFI_type_ptrdiff_t (CFI_type_Integer + (sizeof (ptrdiff_t) << CFI_type_kind_shift))
-#define CFI_type_Bool (CFI_type_Logical + (sizeof (_Bool) << CFI_type_kind_shift))
-#define CFI_type_float (CFI_type_Real + (sizeof (float) << CFI_type_kind_shift))
-#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))
diff --git a/libgfortran/ISO_Fortran_binding-2-tmpl.h b/libgfortran/ISO_Fortran_binding-2-tmpl.h
deleted file mode 100644
index ad88f8b..0000000
--- a/libgfortran/ISO_Fortran_binding-2-tmpl.h
+++ /dev/null
@@ -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 
diff --git a/libgfortran/ISO_Fortran_binding-3-tmpl.h b/libgfortran/ISO_Fortran_binding-3-tmpl.h
deleted file mode 100644
index aec4288..0000000
--- a/libgfortran/ISO_Fortran_binding-3-tmpl.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ISO_FORTRAN_BINDING_H */
diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h
new file mode 100644
index 0000000..686cc8b
--- /dev/null
+++ b/libgfortran/ISO_Fortran_binding.h
@@ -0,0 +1,273 @@
+/* Declarations for ISO Fortran binding.
+   Copyright (C) 2018-2021 Free Software Foundation, Inc.
+   Contributed by Daniel Celis Garza  <celisdanieljr@gmail.com>
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef ISO_FORTRAN_BINDING_H
+#define ISO_FORTRAN_BINDING_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#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_MAX_RANK 15
+
+/* Attributes. */
+#define CFI_attribute_pointer 0
+#define CFI_attribute_allocatable 1
+#define CFI_attribute_other 2
+
+/* Error codes.
+   Note that CFI_FAILURE and CFI_INVALID_STRIDE are specific to GCC
+   and not part of the Fortran standard   */
+#define CFI_SUCCESS 0
+#define CFI_FAILURE 1
+#define CFI_ERROR_BASE_ADDR_NULL 2
+#define CFI_ERROR_BASE_ADDR_NOT_NULL 3
+#define CFI_INVALID_ELEM_LEN 4
+#define CFI_INVALID_RANK 5
+#define CFI_INVALID_TYPE 6
+#define CFI_INVALID_ATTRIBUTE 7
+#define CFI_INVALID_EXTENT 8
+#define CFI_INVALID_STRIDE 9
+#define CFI_INVALID_DESCRIPTOR 10
+#define CFI_ERROR_MEM_ALLOCATION 11
+#define CFI_ERROR_OUT_OF_BOUNDS 12
+
+/* CFI type definitions. */
+typedef ptrdiff_t CFI_index_t;
+typedef int8_t CFI_rank_t;
+typedef int8_t CFI_attribute_t;
+typedef int16_t CFI_type_t;
+
+/* CFI_dim_t. */
+typedef struct CFI_dim_t
+  {
+    CFI_index_t lower_bound;
+    CFI_index_t extent;
+    CFI_index_t sm;
+  }
+CFI_dim_t;
+
+/* CFI_cdesc_t, C descriptors are cast to this structure as follows:
+   CFI_CDESC_T(CFI_MAX_RANK) foo;
+   CFI_cdesc_t * bar = (CFI_cdesc_t *) &foo;
+ */
+typedef struct CFI_cdesc_t
+ {
+    void *base_addr;
+    size_t elem_len;
+    int version;
+    CFI_rank_t rank;
+    CFI_attribute_t attribute;
+    CFI_type_t type;
+    CFI_dim_t dim[];
+ }
+CFI_cdesc_t;
+
+/* CFI_CDESC_T with an explicit type. */
+#define CFI_CDESC_TYPE_T(r, base_type) \
+	struct { \
+		base_type *base_addr; \
+		size_t elem_len; \
+		int version; \
+		CFI_rank_t rank; \
+		CFI_attribute_t attribute; \
+		CFI_type_t type; \
+		CFI_dim_t dim[r]; \
+	}
+#define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void)
+
+/* CFI function declarations. */
+extern void *CFI_address (const CFI_cdesc_t *, const CFI_index_t []);
+extern int CFI_allocate (CFI_cdesc_t *, const CFI_index_t [], const CFI_index_t [],
+			 size_t);
+extern int CFI_deallocate (CFI_cdesc_t *);
+extern int CFI_establish (CFI_cdesc_t *, void *, CFI_attribute_t, CFI_type_t, size_t,
+			  CFI_rank_t, const CFI_index_t []);
+extern int CFI_is_contiguous (const CFI_cdesc_t *);
+extern int CFI_section (CFI_cdesc_t *, const CFI_cdesc_t *, const CFI_index_t [],
+			const CFI_index_t [], const CFI_index_t []);
+extern int CFI_select_part (CFI_cdesc_t *, const CFI_cdesc_t *, size_t, size_t);
+extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
+
+/* Types and kind numbers. Allows bitwise and to reveal the intrinsic type of a kind type. It also allows us to find the kind parameter by inverting the bit-shift equation.
+   CFI_type_kind_shift = 8
+   CFI_intrinsic_type  = 0 0 0 0 0 0 0 0 0 0 1 0
+   CFI_type_kind       = 0 0 0 0 0 0 0 0 1 0 0 0
+   CFI_type_example    = CFI_intrinsic_type + (CFI_type_kind << CFI_type_kind_shift)
+   Defining the CFI_type_example.
+   CFI_type_kind       = 0 0 0 0 0 0 0 0 1 0 0 0  << CFI_type_kind_shift
+			-------------------------
+			 1 0 0 0 0 0 0 0 0 0 0 0  +
+   CFI_intrinsic_type  = 0 0 0 0 0 0 0 0 0 0 1 0
+			-------------------------
+   CFI_type_example    = 1 0 0 0 0 0 0 0 0 0 1 0
+   Finding the intrinsic type with the logical mask.
+   CFI_type_example    = 1 0 0 0 0 0 0 0 0 0 1 0  &
+   CFI_type_mask       = 0 0 0 0 1 1 1 1 1 1 1 1
+			-------------------------
+   CFI_intrinsic_type  = 0 0 0 0 0 0 0 0 0 0 1 0
+   Using the intrinsic type and kind shift to find the kind value of the type.
+   CFI_type_kind = (CFI_type_example - CFI_intrinsic_type) >> CFI_type_kind_shift
+   CFI_type_example   = 1 0 0 0 0 0 0 0 0 0 1 0  -
+   CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
+			-------------------------
+			1 0 0 0 0 0 0 0 0 0 0 0  >> CFI_type_kind_shift
+			-------------------------
+   CFI_type_kind      = 0 0 0 0 0 0 0 0 1 0 0 0
+ */
+#define CFI_type_mask 0xFF
+#define CFI_type_kind_shift 8
+
+/* Intrinsic types. Their kind number defines their storage size. */
+#define CFI_type_Integer 1
+#define CFI_type_Logical 2
+#define CFI_type_Real 3
+#define CFI_type_Complex 4
+#define CFI_type_Character 5
+
+/* Types with no kind. */
+#define CFI_type_struct 6
+#define CFI_type_cptr 7
+#define CFI_type_cfunptr 8
+#define CFI_type_other -1
+
+/* Types with kind parameter.
+   The kind parameter represents the type's byte size.  The exception is
+   real kind = 10, which has byte size of 128 bits but 80 bit precision.
+   Complex variables are double the byte size of their real counterparts.
+   The ucs4_char matches wchar_t if sizeof (wchar_t) == 4.
+ */
+#define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift))
+#define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift))
+
+/* C-Fortran Interoperability types. */
+#define CFI_type_signed_char (CFI_type_Integer + (sizeof (char) << CFI_type_kind_shift))
+#define CFI_type_short (CFI_type_Integer + (sizeof (short) << CFI_type_kind_shift))
+#define CFI_type_int (CFI_type_Integer + (sizeof (int) << CFI_type_kind_shift))
+#define CFI_type_long (CFI_type_Integer + (sizeof (long) << CFI_type_kind_shift))
+#define CFI_type_long_long (CFI_type_Integer + (sizeof (long long) << CFI_type_kind_shift))
+#define CFI_type_size_t (CFI_type_Integer + (sizeof (size_t) << CFI_type_kind_shift))
+#define CFI_type_int8_t (CFI_type_Integer + (sizeof (int8_t) << CFI_type_kind_shift))
+#define CFI_type_int16_t (CFI_type_Integer + (sizeof (int16_t) << CFI_type_kind_shift))
+#define CFI_type_int32_t (CFI_type_Integer + (sizeof (int32_t) << CFI_type_kind_shift))
+#define CFI_type_int64_t (CFI_type_Integer + (sizeof (int64_t) << CFI_type_kind_shift))
+#define CFI_type_int_least8_t (CFI_type_Integer + (sizeof (int_least8_t) << CFI_type_kind_shift))
+#define CFI_type_int_least16_t (CFI_type_Integer + (sizeof (int_least16_t) << CFI_type_kind_shift))
+#define CFI_type_int_least32_t (CFI_type_Integer + (sizeof (int_least32_t) << CFI_type_kind_shift))
+#define CFI_type_int_least64_t (CFI_type_Integer + (sizeof (int_least64_t) << CFI_type_kind_shift))
+#define CFI_type_int_fast8_t (CFI_type_Integer + (sizeof (int_fast8_t) << CFI_type_kind_shift))
+#define CFI_type_int_fast16_t (CFI_type_Integer + (sizeof (int_fast16_t) << CFI_type_kind_shift))
+#define CFI_type_int_fast32_t (CFI_type_Integer + (sizeof (int_fast32_t) << CFI_type_kind_shift))
+#define CFI_type_int_fast64_t (CFI_type_Integer + (sizeof (int_fast64_t) << CFI_type_kind_shift))
+#define CFI_type_intmax_t (CFI_type_Integer + (sizeof (intmax_t) << CFI_type_kind_shift))
+#define CFI_type_intptr_t (CFI_type_Integer + (sizeof (intptr_t) << CFI_type_kind_shift))
+#define CFI_type_ptrdiff_t (CFI_type_Integer + (sizeof (ptrdiff_t) << CFI_type_kind_shift))
+#define CFI_type_Bool (CFI_type_Logical + (sizeof (_Bool) << CFI_type_kind_shift))
+#define CFI_type_float (CFI_type_Real + (sizeof (float) << CFI_type_kind_shift))
+#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 */
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 8d10432..5874c0d 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -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
diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in
index afe1ed1..22a6942 100644
--- a/libgfortran/Makefile.in
+++ b/libgfortran/Makefile.in
@@ -724,7 +724,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)
 
@@ -7044,15 +7044,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
diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh
index f4244f0..2496190 100755
--- a/libgfortran/mk-kinds-h.sh
+++ b/libgfortran/mk-kinds-h.sh
@@ -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.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* PING Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-08-19  2:57 [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Sandra Loosemore
@ 2021-09-03  2:05 ` Sandra Loosemore
  2021-09-06 19:29 ` Tobias Burnus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 26+ messages in thread
From: Sandra Loosemore @ 2021-09-03  2:05 UTC (permalink / raw)
  To: fortran, gcc-patches; +Cc: Tobias Burnus

On 8/18/21 8:57 PM, Sandra Loosemore wrote:

> This is a follow-up to commit fef67987cf502fe322e92ddce22eea7ac46b4d75:
> 
> https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=fef67987cf502fe322e92ddce22eea7ac46b4d75 
> 
> 
> I realized last week that having multilib-specific versions of 
> ISO_Fortran_binding.h (generated by running the compiler to ask what 
> kinds it supports) was still broken outside of the test support; the 
> directory where it's being installed isn't on GCC's normal search path. 
> It seemed to me that it was better to try to find some other solution 
> for this problem than to venture down what appears to be a rat hole.
> 
> I've come up with this patch to return to a single ISO_Fortran_binding.h 
> file that uses preprocessor magic to identify the Fortran kind 
> corresponding to the standard C long double type and the GCC extension 
> types __float128 and int128_t.  I haven't attempted to undo the 
> follow-up patches that fixed in-tree testing; the static .h file is 
> still copied to the build directory, and it can still be referenced with 
> <> syntax during testing.
> 
> Any complaints about either the overall strategy here, or the logic to 
> infer the C type -> kind mapping?  Or OK to commit?
Ping!

https://gcc.gnu.org/pipermail/fortran/2021-August/056382.html

-Sandra

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-08-19  2:57 [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Sandra Loosemore
  2021-09-03  2:05 ` PING " Sandra Loosemore
@ 2021-09-06 19:29 ` Tobias Burnus
  2021-09-10 15:39 ` Andreas Schwab
  2021-09-13 15:56 ` Gerald Pfeifer
  3 siblings, 0 replies; 26+ messages in thread
From: Tobias Burnus @ 2021-09-06 19:29 UTC (permalink / raw)
  To: Sandra Loosemore, fortran, gcc-patches

On 19.08.21 04:57, Sandra Loosemore wrote:

> This is a follow-up to commit fef67987cf502fe322e92ddce22eea7ac46b4d75:
> https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=fef67987cf502fe322e92ddce22eea7ac46b4d75
>
>
> I realized last week that having multilib-specific versions of
> ISO_Fortran_binding.h (generated by running the compiler to ask what
> kinds it supports) was still broken outside of the test support; the
> directory where it's being installed isn't on GCC's normal search
> path. It seemed to me that it was better to try to find some other
> solution for this problem than to venture down what appears to be a
> rat hole.
>
> I've come up with this patch to return to a single
> ISO_Fortran_binding.h file that uses preprocessor magic to identify
> the Fortran kind corresponding to the standard C long double type and
> the GCC extension types __float128 and int128_t. I haven't attempted
> to undo the follow-up patches that fixed in-tree testing; the static
> .h file is still copied to the build directory, and it can still be
> referenced with <> syntax during testing.
>
> Any complaints about either the overall strategy here, or the logic to
> infer the C type -> kind mapping?  Or OK to commit?

OK.

[I think you need to fix the merge differences due to your
https://gcc.gnu.org/g:93b6b2f614eb692d1d8126ec6cb946984a9d01d7 commit
(regarding CFI_type_cfunptr) when applying the patch.]

I believe that, at some point, we still want to have a multi-lib include
directory, e.g. $(libsubdir)/include-multi/, for those include files
which have to be split per multi lib (+ update GCC's include search
paths). An example would be libgomp's omp.h (→
https://gcc.gnu.org/PR60670). However, that's a separate issue. If
that's available, we can then still decide whether the new solution of
__... feature tests is sufficient or whether it should be then changed
back to multiple include files.

In any case, this patch unbreaks https://sourceware.org/PR28183 which is
surely a good thing :-)

Thanks and sorry for the slow review.

Tobias

PS: One reason for the slow review was that I initially had planned to
include bits of ISO_Fortran_binding.h in the compiler FE for
constructing the CFI descriptor. However, the code started to be that
convoluted and additional #defines were needed. Thus, I have now simply
copied the definitions to gfortran.h + some hard-coded values in
trans-type.c, where the CFI type is constructed. – Thus, you patch does
not interfere with my CFI patch →
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/578904.html

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-08-19  2:57 [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Sandra Loosemore
  2021-09-03  2:05 ` PING " Sandra Loosemore
  2021-09-06 19:29 ` Tobias Burnus
@ 2021-09-10 15:39 ` Andreas Schwab
  2021-09-13  7:51   ` Tobias Burnus
  2021-09-13 15:56 ` Gerald Pfeifer
  3 siblings, 1 reply; 26+ messages in thread
From: Andreas Schwab @ 2021-09-10 15:39 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: fortran, gcc-patches, Tobias Burnus

This misses the m68k extended real format.

Andreas.

	* ISO_Fortran_binding.h (CFI_type_long_double)
	(CFI_type_long_double_Complex) [LDBL_MANT_DIG == 64 &&
	LDBL_MIN_EXP == -16382 && LDBL_MAX_EXP == 16384]: Define.
---
 libgfortran/ISO_Fortran_binding.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h
index 5335ea471c7..9c42464affa 100644
--- a/libgfortran/ISO_Fortran_binding.h
+++ b/libgfortran/ISO_Fortran_binding.h
@@ -233,6 +233,13 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
 #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 96-bit encoding on m68k; Fortran assigns it kind 10.  */
+#elif (LDBL_MANT_DIG == 64 \
+       && LDBL_MIN_EXP == -16382 \
+       && 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 \
-- 
2.33.0

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-10 15:39 ` Andreas Schwab
@ 2021-09-13  7:51   ` Tobias Burnus
  0 siblings, 0 replies; 26+ messages in thread
From: Tobias Burnus @ 2021-09-13  7:51 UTC (permalink / raw)
  To: Andreas Schwab, Sandra Loosemore; +Cc: fortran, gcc-patches, Tobias Burnus

On 10.09.21 17:39, Andreas Schwab wrote:
> This misses the m68k extended real format.
>
>       * ISO_Fortran_binding.h (CFI_type_long_double)
>       (CFI_type_long_double_Complex) [LDBL_MANT_DIG == 64 &&
>       LDBL_MIN_EXP == -16382 && LDBL_MAX_EXP == 16384]: Define.

LGTM – thanks!

Tobias

> ---
>   libgfortran/ISO_Fortran_binding.h | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h
> index 5335ea471c7..9c42464affa 100644
> --- a/libgfortran/ISO_Fortran_binding.h
> +++ b/libgfortran/ISO_Fortran_binding.h
> @@ -233,6 +233,13 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
>   #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 96-bit encoding on m68k; Fortran assigns it kind 10.  */
> +#elif (LDBL_MANT_DIG == 64 \
> +       && LDBL_MIN_EXP == -16382 \
> +       && 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 \
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-08-19  2:57 [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Sandra Loosemore
                   ` (2 preceding siblings ...)
  2021-09-10 15:39 ` Andreas Schwab
@ 2021-09-13 15:56 ` Gerald Pfeifer
  2021-09-13 16:32   ` Tobias Burnus
                     ` (2 more replies)
  3 siblings, 3 replies; 26+ messages in thread
From: Gerald Pfeifer @ 2021-09-13 15:56 UTC (permalink / raw)
  To: Sandra Loosemore, Andreas Tobler; +Cc: fortran, gcc-patches, Tobias Burnus

On Wed, 18 Aug 2021, Sandra Loosemore wrote:
> I realized last week that having multilib-specific versions of
> ISO_Fortran_binding.h (generated by running the compiler to ask what kinds it
> supports) was still broken outside of the test support; the directory where
> it's being installed isn't on GCC's normal search path. It seemed to me that
> it was better to try to find some other solution for this problem than to
> venture down what appears to be a rat hole.
> 
> I've come up with this patch to return to a single ISO_Fortran_binding.h file
> that uses preprocessor magic to identify the Fortran kind corresponding to the
> standard C long double type and the GCC extension types __float128 and
> int128_t.
:
>  2021-08-18  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 broke bootstrap on i586-unknown-freebsd11:

  In file included from .../GCC-HEAD/libgfortran/runtime/ISO_Fortran_binding.c:30:
  .../GCC-HEAD/libgfortran/ISO_Fortran_binding.h:255:2: 
  error: #error "Can't determine kind of long double"
  255 | #error "Can't determine kind of long double"
      |  ^~~~~

Does this work on i586-*-linux?


% egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
/usr/include/x86/float.h:#define LDBL_MANT_DIG  64
/usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
/usr/include/x86/float.h:#define LDBL_MAX_EXP   16384

This looks like it matches existing Linux case already in place?


Hmm, I wonder whether this may be related to the bootstrap compiler,
which is clang 10.0.1 on FreeBSD 11 and 12.  Apparently not, since 
even setting CC and CXX to recent GCC builds the same issue occurs.

(Note this happens after stage 3, so in hindsight not too surprising
that it's independent of the bootstrap compiler.)

Gerald

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 15:56 ` Gerald Pfeifer
@ 2021-09-13 16:32   ` Tobias Burnus
  2021-09-13 16:51     ` Jakub Jelinek
  2021-09-14 14:50     ` Gerald Pfeifer
  2021-09-13 17:39   ` [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Andreas Schwab
  2021-09-13 18:07   ` Jakub Jelinek
  2 siblings, 2 replies; 26+ messages in thread
From: Tobias Burnus @ 2021-09-13 16:32 UTC (permalink / raw)
  To: Gerald Pfeifer, Sandra Loosemore, Andreas Tobler; +Cc: fortran, gcc-patches

Hi Gerald,

On 13.09.21 17:56, Gerald Pfeifer wrote:
> This broke bootstrap on i586-unknown-freebsd11:
>
>    In file included from .../GCC-HEAD/libgfortran/runtime/ISO_Fortran_binding.c:30:
>    .../GCC-HEAD/libgfortran/ISO_Fortran_binding.h:255:2:
>    error: #error "Can't determine kind of long double"
>    255 | #error "Can't determine kind of long double"
>        |  ^~~~~
>
> Does this work on i586-*-linux?
>
>
> % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
> /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
> /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
> /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
>
> This looks like it matches existing Linux case already in place?

Can you run 'echo | cpp -E -g3|grep DBL' to (or in the build dir: echo |
./gcc/cc1 -E -g3 -dD|grep DBL) to check what's the output?

It might be that /usr/include/x86/float.h is not used; e.g. there is
$(gcc-src)/ginclude/float.h which undef's the LDBL_MAX_EXP to replace it
by a #define using __LDBL_MAX_EXP. Thus, if those are different from the
values under /usr/include, it might be the reason for the fail?

I think it works under Linux, at least the "x86-64 -m32"
libgfortran.{so,a}  build and the -m32 testsuite runs do work.

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 16:32   ` Tobias Burnus
@ 2021-09-13 16:51     ` Jakub Jelinek
  2021-09-13 16:59       ` Sandra Loosemore
  2021-09-14 14:50     ` Gerald Pfeifer
  1 sibling, 1 reply; 26+ messages in thread
From: Jakub Jelinek @ 2021-09-13 16:51 UTC (permalink / raw)
  To: Tobias Burnus
  Cc: Gerald Pfeifer, Sandra Loosemore, Andreas Tobler, gcc-patches, fortran

On Mon, Sep 13, 2021 at 06:32:56PM +0200, Tobias Burnus wrote:
> On 13.09.21 17:56, Gerald Pfeifer wrote:
> > This broke bootstrap on i586-unknown-freebsd11:
> > 
> >    In file included from .../GCC-HEAD/libgfortran/runtime/ISO_Fortran_binding.c:30:
> >    .../GCC-HEAD/libgfortran/ISO_Fortran_binding.h:255:2:
> >    error: #error "Can't determine kind of long double"
> >    255 | #error "Can't determine kind of long double"
> >        |  ^~~~~
> > 
> > Does this work on i586-*-linux?
> > 
> > 
> > % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
> > /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
> > /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
> > /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
> > 
> > This looks like it matches existing Linux case already in place?
> 
> Can you run 'echo | cpp -E -g3|grep DBL' to (or in the build dir: echo |
> ./gcc/cc1 -E -g3 -dD|grep DBL) to check what's the output?
> 
> It might be that /usr/include/x86/float.h is not used; e.g. there is
> $(gcc-src)/ginclude/float.h which undef's the LDBL_MAX_EXP to replace it
> by a #define using __LDBL_MAX_EXP. Thus, if those are different from the
> values under /usr/include, it might be the reason for the fail?
> 
> I think it works under Linux, at least the "x86-64 -m32"
> libgfortran.{so,a}  build and the -m32 testsuite runs do work.

Wouldn't it be better to use the __LDBL_* macros anyway and not rely on
float.h?  The header doesn't want to test what float.h tells about the
long double type, but what the compiler knows about it.

	Jakub


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 16:51     ` Jakub Jelinek
@ 2021-09-13 16:59       ` Sandra Loosemore
  2021-09-13 17:07         ` Tobias Burnus
  0 siblings, 1 reply; 26+ messages in thread
From: Sandra Loosemore @ 2021-09-13 16:59 UTC (permalink / raw)
  To: Jakub Jelinek, Tobias Burnus
  Cc: Gerald Pfeifer, Andreas Tobler, gcc-patches, fortran

On 9/13/21 10:51 AM, Jakub Jelinek wrote:
> On Mon, Sep 13, 2021 at 06:32:56PM +0200, Tobias Burnus wrote:
>> On 13.09.21 17:56, Gerald Pfeifer wrote:
>>> This broke bootstrap on i586-unknown-freebsd11:
>>>
>>>     In file included from .../GCC-HEAD/libgfortran/runtime/ISO_Fortran_binding.c:30:
>>>     .../GCC-HEAD/libgfortran/ISO_Fortran_binding.h:255:2:
>>>     error: #error "Can't determine kind of long double"
>>>     255 | #error "Can't determine kind of long double"
>>>         |  ^~~~~
>>>
>>> Does this work on i586-*-linux?
>>>
>>>
>>> % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
>>> /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
>>> /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
>>> /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
>>>
>>> This looks like it matches existing Linux case already in place?
>>
>> Can you run 'echo | cpp -E -g3|grep DBL' to (or in the build dir: echo |
>> ./gcc/cc1 -E -g3 -dD|grep DBL) to check what's the output?
>>
>> It might be that /usr/include/x86/float.h is not used; e.g. there is
>> $(gcc-src)/ginclude/float.h which undef's the LDBL_MAX_EXP to replace it
>> by a #define using __LDBL_MAX_EXP. Thus, if those are different from the
>> values under /usr/include, it might be the reason for the fail?
>>
>> I think it works under Linux, at least the "x86-64 -m32"
>> libgfortran.{so,a}  build and the -m32 testsuite runs do work.
> 
> Wouldn't it be better to use the __LDBL_* macros anyway and not rely on
> float.h?  The header doesn't want to test what float.h tells about the
> long double type, but what the compiler knows about it.

I originally wrote the code to use the internal GCC __LDBL_* macros as 
you suggest, but Tobias complained that then the gfortran-provided .h 
file could not be used to compile the C parts of the program with some 
other C compiler.  (I guess there are people out in the real world who 
want to mash up clang-compiled C code with gfortran programs).  Maybe it 
needs to first check the internal macros and then look for the float.h 
versions if it can't find them?

-Sandra

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 16:59       ` Sandra Loosemore
@ 2021-09-13 17:07         ` Tobias Burnus
  2021-09-13 17:20           ` Jakub Jelinek
  2021-09-14  3:39           ` Sandra Loosemore
  0 siblings, 2 replies; 26+ messages in thread
From: Tobias Burnus @ 2021-09-13 17:07 UTC (permalink / raw)
  To: Sandra Loosemore, Jakub Jelinek
  Cc: Gerald Pfeifer, Andreas Tobler, gcc-patches, fortran

On 13.09.21 18:59, Sandra Loosemore wrote:
> On 9/13/21 10:51 AM, Jakub Jelinek wrote:
>> On Mon, Sep 13, 2021 at 06:32:56PM +0200, Tobias Burnus wrote:
>>> On 13.09.21 17:56, Gerald Pfeifer wrote:
>>>> This broke bootstrap on i586-unknown-freebsd11:
>>>>
>>>> % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
>>>> /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
>>>> /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
>>>> /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
>>>>
>>>> This looks like it matches existing Linux case already in place?
>>>
>>> Can you run 'echo | cpp -E -g3|grep DBL' to (or in the build dir:
>>> echo |
>>> ./gcc/cc1 -E -g3 -dD|grep DBL) to check what's the output?

Regarding FreeBSD: Does this output different values? – If yes, we know
what to do, otherwise – hmm.

[...]

>> Wouldn't it be better to use the __LDBL_* macros anyway and not rely on
>> float.h?  The header doesn't want to test what float.h tells about the
>> long double type, but what the compiler knows about it.
> I originally wrote the code to use the internal GCC __LDBL_* macros as
> you suggest, but Tobias complained that then the gfortran-provided .h
> file could not be used to compile the C parts of the program with some
> other C compiler.
For instance, clang does not seem to provide those - and in some cases,
it can be useful to mix gfortran code with code complied by other
compilers (icc, clang, ...).
> Maybe it needs to first check the internal macros and then look for
> the float.h versions if it can't find them?

I think that makes sense. (Adding a comment that #include <float.h> is
for non-GCC compilers, only.)

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 17:07         ` Tobias Burnus
@ 2021-09-13 17:20           ` Jakub Jelinek
  2021-09-14  3:39           ` Sandra Loosemore
  1 sibling, 0 replies; 26+ messages in thread
From: Jakub Jelinek @ 2021-09-13 17:20 UTC (permalink / raw)
  To: Tobias Burnus
  Cc: Sandra Loosemore, Gerald Pfeifer, Andreas Tobler, gcc-patches, fortran

On Mon, Sep 13, 2021 at 07:07:01PM +0200, Tobias Burnus wrote:
> Regarding FreeBSD: Does this output different values? – If yes, we know
> what to do, otherwise – hmm.
> 
> [...]
> 
> > > Wouldn't it be better to use the __LDBL_* macros anyway and not rely on
> > > float.h?  The header doesn't want to test what float.h tells about the
> > > long double type, but what the compiler knows about it.
> > I originally wrote the code to use the internal GCC __LDBL_* macros as
> > you suggest, but Tobias complained that then the gfortran-provided .h
> > file could not be used to compile the C parts of the program with some
> > other C compiler.
> For instance, clang does not seem to provide those - and in some cases,
> it can be useful to mix gfortran code with code complied by other
> compilers (icc, clang, ...).
> > Maybe it needs to first check the internal macros and then look for
> > the float.h versions if it can't find them?
> 
> I think that makes sense. (Adding a comment that #include <float.h> is
> for non-GCC compilers, only.)

At least according to godbolt and my tests, both clang and icc predefine
those macros too.  But there are other C compilers, sure.

So we'd need #if defined (__LDBL_MAX__) && defined (__LDBL_*_) // whatever
we need
#else
#include <float.h>
...
#endif
or so.

	Jakub


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 15:56 ` Gerald Pfeifer
  2021-09-13 16:32   ` Tobias Burnus
@ 2021-09-13 17:39   ` Andreas Schwab
  2021-09-13 18:07   ` Jakub Jelinek
  2 siblings, 0 replies; 26+ messages in thread
From: Andreas Schwab @ 2021-09-13 17:39 UTC (permalink / raw)
  To: Gerald Pfeifer
  Cc: Sandra Loosemore, Andreas Tobler, Tobias Burnus, gcc-patches, fortran

On Sep 13 2021, Gerald Pfeifer wrote:

> % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
> /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
> /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
> /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
>
> This looks like it matches existing Linux case already in place?

gcc has its own <float.h>, see gcc/include/float.h in the build
directory.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 15:56 ` Gerald Pfeifer
  2021-09-13 16:32   ` Tobias Burnus
  2021-09-13 17:39   ` [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Andreas Schwab
@ 2021-09-13 18:07   ` Jakub Jelinek
  2 siblings, 0 replies; 26+ messages in thread
From: Jakub Jelinek @ 2021-09-13 18:07 UTC (permalink / raw)
  To: Gerald Pfeifer
  Cc: Sandra Loosemore, Andreas Tobler, Tobias Burnus, gcc-patches, fortran

On Mon, Sep 13, 2021 at 05:56:53PM +0200, Gerald Pfeifer wrote:
> % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)' /usr/include/
> /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
> /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
> /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
> 
> This looks like it matches existing Linux case already in place?

Those are indeed the same.  But perhaps the FreeBSD float.h header
guards those defines with some preprocessor condition?

	Jakub


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 17:07         ` Tobias Burnus
  2021-09-13 17:20           ` Jakub Jelinek
@ 2021-09-14  3:39           ` Sandra Loosemore
  2021-09-14  7:39             ` Tobias Burnus
  2021-09-14 16:34             ` Gerald Pfeifer
  1 sibling, 2 replies; 26+ messages in thread
From: Sandra Loosemore @ 2021-09-14  3:39 UTC (permalink / raw)
  To: Tobias Burnus, Jakub Jelinek
  Cc: Gerald Pfeifer, Andreas Tobler, gcc-patches, fortran

[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]

On 9/13/21 11:07 AM, Tobias Burnus wrote:
> On 13.09.21 18:59, Sandra Loosemore wrote:
>> On 9/13/21 10:51 AM, Jakub Jelinek wrote: >>> Wouldn't it be better to use the __LDBL_* macros anyway and not rely on
>>> float.h?  The header doesn't want to test what float.h tells about the
>>> long double type, but what the compiler knows about it.
>> I originally wrote the code to use the internal GCC __LDBL_* macros as 
>> you suggest, but Tobias complained that then the gfortran-provided .h 
>> file could not be used to compile the C parts of the program with some 
>> other C compiler. 
> For instance, clang does not seem to provide those - and in some cases, 
> it can be useful to mix gfortran code with code complied by other 
> compilers (icc, clang, ...).
>> Maybe it needs to first check the internal macros and then look for 
>> the float.h versions if it can't find them?
> 
> I think that makes sense. (Adding a comment that #include <float.h> is 
> for non-GCC compilers, only.)

Here's a patch.  Gerald, can you check that this fixes your bootstrap 
problem on i586-unknown-freebsd11?

-Sandra

[-- Attachment #2: ldbl-macro-fix.patch --]
[-- Type: text/x-patch, Size: 4931 bytes --]

commit b8b19bca743ed678ef1b59f1a363c7fa7d155c43
Author: Sandra Loosemore <sandra@codesourcery.com>
Date:   Mon Sep 13 19:48:16 2021 -0700

    Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h.
    
    2021-09-13  Sandra Loosemore  <sandra@codesourcery.com>
    
    	libgfortran/
    	* ISO_Fortran_binding.h: Only include float.h if the C compiler
    	doesn't have predefined __LDBL_* and __DBL_* macros.

diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h
index 9c42464..a3c6f80 100644
--- a/libgfortran/ISO_Fortran_binding.h
+++ b/libgfortran/ISO_Fortran_binding.h
@@ -32,7 +32,6 @@ 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
@@ -217,40 +216,82 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
 #endif
 
 /* The situation with long double support is more complicated; we need to
-   examine the type in more detail to figure out its kind.  */
+   examine the type in more detail to figure out its kind.
+   GCC and some other compilers predefine the __LDBL* macros; otherwise
+   get the parameters we need from float.h.  */
+
+#if (defined (__LDBL_MANT_DIG__) \
+     && defined (__LDBL_MIN_EXP__) \
+     && defined (__LDBL_MAX_EXP__) \
+     && defined (__DBL_MANT_DIG__) \
+     && defined (__DBL_MIN_EXP__) \
+     && defined (__DBL_MAX_EXP__))
+#define __CFI_LDBL_MANT_DIG__ __LDBL_MANT_DIG__
+#define __CFI_LDBL_MIN_EXP__ __LDBL_MIN_EXP__
+#define __CFI_LDBL_MAX_EXP__ __LDBL_MAX_EXP__
+#define __CFI_DBL_MANT_DIG__ __DBL_MANT_DIG__
+#define __CFI_DBL_MIN_EXP__ __DBL_MIN_EXP__
+#define __CFI_DBL_MAX_EXP__ __DBL_MAX_EXP__
+
+#else
+#include <float.h>
+
+#if (defined (LDBL_MANT_DIG) \
+     && defined (LDBL_MIN_EXP) \
+     && defined (LDBL_MAX_EXP) \
+     && defined (DBL_MANT_DIG) \
+     && defined (DBL_MIN_EXP) \
+     && defined (DBL_MAX_EXP))
+#define __CFI_LDBL_MANT_DIG__ LDBL_MANT_DIG
+#define __CFI_LDBL_MIN_EXP__ LDBL_MIN_EXP
+#define __CFI_LDBL_MAX_EXP__ LDBL_MAX_EXP
+#define __CFI_DBL_MANT_DIG__ DBL_MANT_DIG
+#define __CFI_DBL_MIN_EXP__ DBL_MIN_EXP
+#define __CFI_DBL_MAX_EXP__ DBL_MAX_EXP
+
+#else
+#define CFI_no_long_double 1
+
+#endif  /* Definitions from float.h.  */
+#endif  /* Definitions from compiler builtins.  */
+
+/* Can't determine anything about long double support?  */
+#if (defined (CFI_no_long_double))
+#define CFI_type_long_double -2
+#define CFI_type_long_double_Complex -2
 
 /* 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)
+#elif (__CFI_LDBL_MANT_DIG__ == __CFI_DBL_MANT_DIG__ \
+     && __CFI_LDBL_MIN_EXP__ == __CFI_DBL_MIN_EXP__ \
+     && __CFI_LDBL_MAX_EXP__ == __CFI_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)
+#elif (__CFI_LDBL_MANT_DIG__ == 64 \
+       && __CFI_LDBL_MIN_EXP__ == -16381 \
+       && __CFI_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 96-bit encoding on m68k; Fortran assigns it kind 10.  */
-#elif (LDBL_MANT_DIG == 64 \
-       && LDBL_MIN_EXP == -16382 \
-       && LDBL_MAX_EXP == 16384)
+#elif (__CFI_LDBL_MANT_DIG__ == 64 \
+       && __CFI_LDBL_MIN_EXP__ == -16382 \
+       && __CFI_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)
+#elif (__CFI_LDBL_MANT_DIG__ == 113 \
+       && __CFI_LDBL_MIN_EXP__ == -16381 \
+       && __CFI_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)
+#elif (__CFI_LDBL_MANT_DIG__ == 106 \
+       && __CFI_LDBL_MIN_EXP__ == -968 \
+       && __CFI_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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14  3:39           ` Sandra Loosemore
@ 2021-09-14  7:39             ` Tobias Burnus
  2021-09-14 16:34             ` Gerald Pfeifer
  1 sibling, 0 replies; 26+ messages in thread
From: Tobias Burnus @ 2021-09-14  7:39 UTC (permalink / raw)
  To: Sandra Loosemore, Tobias Burnus, Jakub Jelinek
  Cc: Gerald Pfeifer, Andreas Tobler, gcc-patches, fortran

On 14.09.21 05:39, Sandra Loosemore wrote:
> Here's a patch.  Gerald, can you check that this fixes your bootstrap
> problem on i586-unknown-freebsd11?

LGTM – thanks!

Tobias

> Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h.
>
>      2021-09-13  Sandra Loosemore<sandra@codesourcery.com>
>
>       libgfortran/
>       * ISO_Fortran_binding.h: Only include float.h if the C compiler
>       doesn't have predefined __LDBL_* and __DBL_* macros.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-13 16:32   ` Tobias Burnus
  2021-09-13 16:51     ` Jakub Jelinek
@ 2021-09-14 14:50     ` Gerald Pfeifer
  2021-09-14 15:16       ` Tobias Burnus
  2021-09-14 15:17       ` Andreas Schwab
  1 sibling, 2 replies; 26+ messages in thread
From: Gerald Pfeifer @ 2021-09-14 14:50 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Sandra Loosemore, Andreas Tobler, fortran, gcc-patches

On Mon, 13 Sep 2021, Tobias Burnus wrote:
> Can you run 'echo | cpp -E -g3|grep DBL' to (or in the build dir: echo |
> ./gcc/cc1 -E -g3 -dD|grep DBL) to check what's the output?

Thank you, Tobias, and I'm just testing the proposed patch, but still
wanted to follow up on your question:

  % echo | ./gcc/cc1 -E -g3 -dD | grep DBL
  #define __DBL_MANT_DIG__ 53
  #define __DBL_DIG__ 15
  #define __DBL_MIN_EXP__ (-1021)
  #define __DBL_MIN_10_EXP__ (-307)
  #define __DBL_MAX_EXP__ 1024
  #define __DBL_MAX_10_EXP__ 308
  #define __DBL_DECIMAL_DIG__ 17
  #define __DBL_MAX__ ((double)1.79769313486231570814527423731704357e+308L)
  #define __DBL_NORM_MAX__ ((double)1.79769313486231570814527423731704357e+308L)
  #define __DBL_MIN__ ((double)2.22507385850720138309023271733240406e-308L)
  #define __DBL_EPSILON__ ((double)2.22044604925031308084726333618164062e-16L)
  #define __DBL_DENORM_MIN__ ((double)4.94065645841246544176568792868221372e-324L)
  #define __DBL_HAS_DENORM__ 1
  #define __DBL_HAS_INFINITY__ 1
  #define __DBL_HAS_QUIET_NAN__ 1
  #define __DBL_IS_IEC_60559__ 2
  #define __LDBL_MANT_DIG__ 53
  #define __LDBL_DIG__ 15
  #define __LDBL_MIN_EXP__ (-16381)
  #define __LDBL_MIN_10_EXP__ (-4931)
  #define __LDBL_MAX_EXP__ 16384
  #define __LDBL_MAX_10_EXP__ 4932
  #define __LDBL_DECIMAL_DIG__ 17
  #define __LDBL_MAX__ 1.18973149535723163299902939989638351e+4932L
  #define __LDBL_NORM_MAX__ 1.18973149535723163299902939989638351e+4932L
  #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
  #define __LDBL_EPSILON__ 2.22044604925031308084726333618164062e-16L
  #define __LDBL_DENORM_MIN__ 7.46536864129530798597817535205257178e-4948L
  #define __LDBL_HAS_DENORM__ 1
  #define __LDBL_HAS_INFINITY__ 1
  #define __LDBL_HAS_QUIET_NAN__ 1
  #define __LDBL_IS_IEC_60559__ 2

Gerald

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 14:50     ` Gerald Pfeifer
@ 2021-09-14 15:16       ` Tobias Burnus
  2021-09-14 15:17       ` Andreas Schwab
  1 sibling, 0 replies; 26+ messages in thread
From: Tobias Burnus @ 2021-09-14 15:16 UTC (permalink / raw)
  To: Gerald Pfeifer; +Cc: Sandra Loosemore, Andreas Tobler, fortran, gcc-patches

Hi Gerald,

I note:

On 13.09.21 17:56, Gerald Pfeifer wrote:
> % egrep -r '#define.*LDBL_(MANT_DIG|MIN_EXP|MAX_EXP)'/usr/include/
> /usr/include/x86/float.h:#define LDBL_MANT_DIG  64
> /usr/include/x86/float.h:#define LDBL_MIN_EXP   (-16381)
> /usr/include/x86/float.h:#define LDBL_MAX_EXP   16384
>
> This looks like it matches existing Linux case already in place?
On 14.09.21 16:50, Gerald Pfeifer wrote:
> On Mon, 13 Sep 2021, Tobias Burnus wrote:
>> Can you run 'echo | cpp -E -g3|grep DBL' to (or in the build dir: echo |
>> ./gcc/cc1 -E -g3 -dD|grep DBL) to check what's the output?
> Thank you, Tobias, and I'm just testing the proposed patch, but still
> wanted to follow up on your question:
>
>    % echo | ./gcc/cc1 -E -g3 -dD | grep DBL
>    #define __DBL_MANT_DIG__ 53
>    #define __DBL_MIN_EXP__ (-1021)
>    #define __DBL_MAX_EXP__ 1024
>
>    #define __LDBL_MANT_DIG__ 53
>    #define __LDBL_MIN_EXP__ (-16381)
>    #define __LDBL_MAX_EXP__ 16384

I note that LDBL_MANT_DIG is 53 as for "double" – while Linux
and your header file has 64. On the other hand, MIN/MAX_EXP for
"long double" are larger than "double" – and match the values
from Linux and the size in your header file.

Thus, the first question is: why does DBL_MANT_DIG differ (64 vs. 53)?

And, related, does the following make sense and fixes the issue?

--- a/libgfortran/ISO_Fortran_binding.h
+++ b/libgfortran/ISO_Fortran_binding.h
@@ -228,5 +228,5 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);

  /* This is the 80-bit encoding on x86; Fortran assigns it kind 10.  */
-#elif (LDBL_MANT_DIG == 64 \
+#elif ((LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 53) \
         && LDBL_MIN_EXP == -16381 \
         && LDBL_MAX_EXP == 16384)

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 14:50     ` Gerald Pfeifer
  2021-09-14 15:16       ` Tobias Burnus
@ 2021-09-14 15:17       ` Andreas Schwab
  2021-09-14 15:23         ` Jakub Jelinek
  1 sibling, 1 reply; 26+ messages in thread
From: Andreas Schwab @ 2021-09-14 15:17 UTC (permalink / raw)
  To: Gerald Pfeifer
  Cc: Tobias Burnus, Sandra Loosemore, gcc-patches, Andreas Tobler, fortran

On Sep 14 2021, Gerald Pfeifer wrote:

>   #define __LDBL_MANT_DIG__ 53
>   #define __LDBL_DIG__ 15
>   #define __LDBL_MIN_EXP__ (-16381)
>   #define __LDBL_MIN_10_EXP__ (-4931)
>   #define __LDBL_MAX_EXP__ 16384
>   #define __LDBL_MAX_10_EXP__ 4932
>   #define __LDBL_DECIMAL_DIG__ 17
>   #define __LDBL_MAX__ 1.18973149535723163299902939989638351e+4932L
>   #define __LDBL_NORM_MAX__ 1.18973149535723163299902939989638351e+4932L
>   #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
>   #define __LDBL_EPSILON__ 2.22044604925031308084726333618164062e-16L
>   #define __LDBL_DENORM_MIN__ 7.46536864129530798597817535205257178e-4948L
>   #define __LDBL_HAS_DENORM__ 1
>   #define __LDBL_HAS_INFINITY__ 1
>   #define __LDBL_HAS_QUIET_NAN__ 1
>   #define __LDBL_IS_IEC_60559__ 2

That looks like range of extended float, but rounded to double float
precision.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 15:17       ` Andreas Schwab
@ 2021-09-14 15:23         ` Jakub Jelinek
  2021-09-14 15:30           ` Andreas Schwab
  2021-09-14 19:27           ` Gerald Pfeifer
  0 siblings, 2 replies; 26+ messages in thread
From: Jakub Jelinek @ 2021-09-14 15:23 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Gerald Pfeifer, Tobias Burnus, Sandra Loosemore, gcc-patches,
	Andreas Tobler, fortran

On Tue, Sep 14, 2021 at 05:17:04PM +0200, Andreas Schwab wrote:
> On Sep 14 2021, Gerald Pfeifer wrote:
> 
> >   #define __LDBL_MANT_DIG__ 53
> >   #define __LDBL_DIG__ 15
> >   #define __LDBL_MIN_EXP__ (-16381)
> >   #define __LDBL_MIN_10_EXP__ (-4931)
> >   #define __LDBL_MAX_EXP__ 16384
> >   #define __LDBL_MAX_10_EXP__ 4932
> >   #define __LDBL_DECIMAL_DIG__ 17
> >   #define __LDBL_MAX__ 1.18973149535723163299902939989638351e+4932L
> >   #define __LDBL_NORM_MAX__ 1.18973149535723163299902939989638351e+4932L
> >   #define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L
> >   #define __LDBL_EPSILON__ 2.22044604925031308084726333618164062e-16L
> >   #define __LDBL_DENORM_MIN__ 7.46536864129530798597817535205257178e-4948L
> >   #define __LDBL_HAS_DENORM__ 1
> >   #define __LDBL_HAS_INFINITY__ 1
> >   #define __LDBL_HAS_QUIET_NAN__ 1
> >   #define __LDBL_IS_IEC_60559__ 2
> 
> That looks like range of extended float, but rounded to double float
> precision.

Yeah.
real.c has:
/* The following caters to i386 systems that set the rounding precision
   to 53 bits instead of 64, e.g. FreeBSD.  */
const struct real_format ieee_extended_intel_96_round_53_format =
But, wonder why it didn't work with the float.h include then, because
https://github.com/lattera/freebsd/blob/master/sys/x86/include/float.h
seems to define LDBL_MANT_DIG to 64, LDBL_MIN_EXP to (-16381) and
LDBL_MAX_EXP to 16384 and that case was handled in ISO_Fortran_binding.h.

	Jakub


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 15:23         ` Jakub Jelinek
@ 2021-09-14 15:30           ` Andreas Schwab
  2021-09-15  1:05             ` Joseph Myers
  2021-09-14 19:27           ` Gerald Pfeifer
  1 sibling, 1 reply; 26+ messages in thread
From: Andreas Schwab @ 2021-09-14 15:30 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Gerald Pfeifer, Tobias Burnus, Sandra Loosemore, gcc-patches,
	Andreas Tobler, fortran

On Sep 14 2021, Jakub Jelinek wrote:

> But, wonder why it didn't work with the float.h include then, because
> https://github.com/lattera/freebsd/blob/master/sys/x86/include/float.h
> seems to define LDBL_MANT_DIG to 64, LDBL_MIN_EXP to (-16381) and
> LDBL_MAX_EXP to 16384 and that case was handled in ISO_Fortran_binding.h.

Doesn't gcc always use its own float.h?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14  3:39           ` Sandra Loosemore
  2021-09-14  7:39             ` Tobias Burnus
@ 2021-09-14 16:34             ` Gerald Pfeifer
  1 sibling, 0 replies; 26+ messages in thread
From: Gerald Pfeifer @ 2021-09-14 16:34 UTC (permalink / raw)
  To: Sandra Loosemore
  Cc: Tobias Burnus, Jakub Jelinek, Andreas Tobler, gcc-patches, fortran

On Mon, 13 Sep 2021, Sandra Loosemore wrote:
> Here's a patch.  Gerald, can you check that this fixes your bootstrap 
> problem on i586-unknown-freebsd11?

I does not change the bootstrap failure on i586-unknown-freebsd11
- though looking at the discussion here still looks like a good 
change to make?


And I just kicked off testing Tobias' suggestion on top of an
unpatched tree and will let you know:

   /* This is the 80-bit encoding on x86; Fortran assigns it kind 10.  */
  -#elif (LDBL_MANT_DIG == 64 \
  +#elif ((LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 53) \
          && LDBL_MIN_EXP == -16381 \
          && LDBL_MAX_EXP == 16384)

Gerald

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 15:23         ` Jakub Jelinek
  2021-09-14 15:30           ` Andreas Schwab
@ 2021-09-14 19:27           ` Gerald Pfeifer
  2021-09-17  6:03             ` Gerald Pfeifer
  1 sibling, 1 reply; 26+ messages in thread
From: Gerald Pfeifer @ 2021-09-14 19:27 UTC (permalink / raw)
  To: Tobias Burnus, Jakub Jelinek
  Cc: Andreas Schwab, Sandra Loosemore, Andreas Tobler, fortran, gcc-patches

On Tue, 14 Sep 2021, Tobias Burnus wrote:
> And, related, does the following make sense and fixes the issue?
> 
> --- a/libgfortran/ISO_Fortran_binding.h
> +++ b/libgfortran/ISO_Fortran_binding.h
> @@ -228,5 +228,5 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *,
> const CFI_index_t []);
> 
>  /* This is the 80-bit encoding on x86; Fortran assigns it kind 10.  */
> -#elif (LDBL_MANT_DIG == 64 \
> +#elif ((LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 53) \
>         && LDBL_MIN_EXP == -16381 \
>         && LDBL_MAX_EXP == 16384)

Yes, with this patch (on top of current trunk) i586-freebsd-* is back
in bootstrap land. :)

On Tue, 14 Sep 2021, Jakub Jelinek wrote:
>> That looks like range of extended float, but rounded to double float
>> precision.
> Yeah.
> real.c has:
> /* The following caters to i386 systems that set the rounding precision
>    to 53 bits instead of 64, e.g. FreeBSD.  */
> const struct real_format ieee_extended_intel_96_round_53_format =
> But, wonder why it didn't work with the float.h include then, because
> https://github.com/lattera/freebsd/blob/master/sys/x86/include/float.h
> seems to define LDBL_MANT_DIG to 64, LDBL_MIN_EXP to (-16381) and
> LDBL_MAX_EXP to 16384 and that case was handled in ISO_Fortran_binding.h.

A friendly soul reminded me off-list "that on i585-*-freebsd, the FPU 
is put into a mode where long double has only 53 bits of precision instead 
of 64 bits. [ /usr/include/x86/fpu.h has ]

/*
 * The hardware default control word for i387's and later coprocessors is
 * 0x37F, giving:
 *
 *      round to nearest
 *      64-bit precision
 *      all exceptions masked.
 *
 * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc
 * because of the difference between memory and fpu register stack arguments.
 * If its using an intermediate fpu register, it has 80/64 bits to work
 * with.  If it uses memory, it has 64/53 bits to work with.  However,
 * gcc is aware of this and goes to a fair bit of trouble to make the
 * best use of it.
 *
 * This is mostly academic for AMD64, because the ABI prefers the use
 * SSE2 based math.  For FreeBSD/amd64, we go with the default settings.
 */
#define __INITIAL_FPUCW__       0x037F
#define __INITIAL_FPUCW_I386__  0x127F
#define __INITIAL_NPXCW__       __INITIAL_FPUCW_I386__
#define __INITIAL_MXCSR__       0x1F80
#define __INITIAL_MXCSR_MASK__  0xFFBF "

(end quote)


Thanks for looking into this together!

Gerald


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 15:30           ` Andreas Schwab
@ 2021-09-15  1:05             ` Joseph Myers
  0 siblings, 0 replies; 26+ messages in thread
From: Joseph Myers @ 2021-09-15  1:05 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Jakub Jelinek, fortran, Sandra Loosemore, gcc-patches,
	Andreas Tobler, Tobias Burnus

On Tue, 14 Sep 2021, Andreas Schwab wrote:

> On Sep 14 2021, Jakub Jelinek wrote:
> 
> > But, wonder why it didn't work with the float.h include then, because
> > https://github.com/lattera/freebsd/blob/master/sys/x86/include/float.h
> > seems to define LDBL_MANT_DIG to 64, LDBL_MIN_EXP to (-16381) and
> > LDBL_MAX_EXP to 16384 and that case was handled in ISO_Fortran_binding.h.
> 
> Doesn't gcc always use its own float.h?

Subject to USER_H (i.e., except on OpenBSD, where GCC tests for newer 
float.h features would probably fail unless OpenBSD's version exactly 
matches the GCC testsuite expectations for those features).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h
  2021-09-14 19:27           ` Gerald Pfeifer
@ 2021-09-17  6:03             ` Gerald Pfeifer
  2021-09-17 14:10               ` [committed] Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h (was: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h) Tobias Burnus
  0 siblings, 1 reply; 26+ messages in thread
From: Gerald Pfeifer @ 2021-09-17  6:03 UTC (permalink / raw)
  To: Tobias Burnus, Jakub Jelinek, Sandra Loosemore
  Cc: Andreas Schwab, Andreas Tobler, fortran, gcc-patches

On Tue, 14 Sep 2021, Gerald Pfeifer wrote:
>> And, related, does the following make sense and fixes the issue?
>> 
>> --- a/libgfortran/ISO_Fortran_binding.h
>> +++ b/libgfortran/ISO_Fortran_binding.h
>> @@ -228,5 +228,5 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *,
>> const CFI_index_t []);
>> 
>>  /* This is the 80-bit encoding on x86; Fortran assigns it kind 10.  */
>> -#elif (LDBL_MANT_DIG == 64 \
>> +#elif ((LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 53) \
>>         && LDBL_MIN_EXP == -16381 \
>>         && LDBL_MAX_EXP == 16384)
> Yes, with this patch (on top of current trunk) i586-freebsd-* is back
> in bootstrap land. :)

Neither this (which fixes the bootstrap) nor Sandra's rewrite (which 
does not, but seemed generally liked) has been committed.

Can someone please push the former (and possibly later)?

Thank you,
Gerald

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [committed] Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h (was: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h)
  2021-09-17  6:03             ` Gerald Pfeifer
@ 2021-09-17 14:10               ` Tobias Burnus
  2021-09-18  4:51                 ` Gerald Pfeifer
  0 siblings, 1 reply; 26+ messages in thread
From: Tobias Burnus @ 2021-09-17 14:10 UTC (permalink / raw)
  To: Gerald Pfeifer, Jakub Jelinek, Sandra Loosemore
  Cc: Andreas Schwab, Andreas Tobler, fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]

On 17.09.21 08:03, Gerald Pfeifer wrote:

> On Tue, 14 Sep 2021, Gerald Pfeifer wrote:
>>> And, related, does the following make sense and fixes the issue?
>>>
>>> --- a/libgfortran/ISO_Fortran_binding.h
>>> +++ b/libgfortran/ISO_Fortran_binding.h
>>> @@ -228,5 +228,5 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *,
>>> const CFI_index_t []);
>>>
>>>   /* This is the 80-bit encoding on x86; Fortran assigns it kind 10.  */
>>> -#elif (LDBL_MANT_DIG == 64 \
>>> +#elif ((LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 53) \
>>>          && LDBL_MIN_EXP == -16381 \
>>>          && LDBL_MAX_EXP == 16384)
>> Yes, with this patch (on top of current trunk) i586-freebsd-* is back
>> in bootstrap land. :)
> Neither this (which fixes the bootstrap) nor Sandra's rewrite (which
> does not, but seemed generally liked) has been committed.
I have now committed the attached patch as r12-3621. It includes the
patch by Sandra
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579372.html
(approved 3 days ago) plus adding the "== 53" similar to above.

Hopefully, we can now close this issue.

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Attachment #2: committed.diff --]
[-- Type: text/x-patch, Size: 5091 bytes --]

commit 654187d05376f08667c8ba88309073e0345431c2
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Fri Sep 17 15:43:30 2021 +0200

    Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h.
    
    2021-09-17  Sandra Loosemore  <sandra@codesourcery.com>
                Tobias Burnus  <tobias@codesourcery.com>
    
    libgfortran/
            * ISO_Fortran_binding.h: Only include float.h if the C compiler
            doesn't have predefined __LDBL_* and __DBL_* macros. Handle
            LDBL_MANT_DIG == 53 for FreeBSD.

diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h
index 9c42464affa..50b02d27c9c 100644
--- a/libgfortran/ISO_Fortran_binding.h
+++ b/libgfortran/ISO_Fortran_binding.h
@@ -32,7 +32,6 @@ 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
@@ -217,40 +216,82 @@ extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
 #endif
 
 /* The situation with long double support is more complicated; we need to
-   examine the type in more detail to figure out its kind.  */
+   examine the type in more detail to figure out its kind.
+   GCC and some other compilers predefine the __LDBL* macros; otherwise
+   get the parameters we need from float.h.  */
+
+#if (defined (__LDBL_MANT_DIG__) \
+     && defined (__LDBL_MIN_EXP__) \
+     && defined (__LDBL_MAX_EXP__) \
+     && defined (__DBL_MANT_DIG__) \
+     && defined (__DBL_MIN_EXP__) \
+     && defined (__DBL_MAX_EXP__))
+#define __CFI_LDBL_MANT_DIG__ __LDBL_MANT_DIG__
+#define __CFI_LDBL_MIN_EXP__ __LDBL_MIN_EXP__
+#define __CFI_LDBL_MAX_EXP__ __LDBL_MAX_EXP__
+#define __CFI_DBL_MANT_DIG__ __DBL_MANT_DIG__
+#define __CFI_DBL_MIN_EXP__ __DBL_MIN_EXP__
+#define __CFI_DBL_MAX_EXP__ __DBL_MAX_EXP__
+
+#else
+#include <float.h>
+
+#if (defined (LDBL_MANT_DIG) \
+     && defined (LDBL_MIN_EXP) \
+     && defined (LDBL_MAX_EXP) \
+     && defined (DBL_MANT_DIG) \
+     && defined (DBL_MIN_EXP) \
+     && defined (DBL_MAX_EXP))
+#define __CFI_LDBL_MANT_DIG__ LDBL_MANT_DIG
+#define __CFI_LDBL_MIN_EXP__ LDBL_MIN_EXP
+#define __CFI_LDBL_MAX_EXP__ LDBL_MAX_EXP
+#define __CFI_DBL_MANT_DIG__ DBL_MANT_DIG
+#define __CFI_DBL_MIN_EXP__ DBL_MIN_EXP
+#define __CFI_DBL_MAX_EXP__ DBL_MAX_EXP
+
+#else
+#define CFI_no_long_double 1
+
+#endif  /* Definitions from float.h.  */
+#endif  /* Definitions from compiler builtins.  */
+
+/* Can't determine anything about long double support?  */
+#if (defined (CFI_no_long_double))
+#define CFI_type_long_double -2
+#define CFI_type_long_double_Complex -2
 
 /* 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)
+#elif (__CFI_LDBL_MANT_DIG__ == __CFI_DBL_MANT_DIG__ \
+     && __CFI_LDBL_MIN_EXP__ == __CFI_DBL_MIN_EXP__ \
+     && __CFI_LDBL_MAX_EXP__ == __CFI_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)
+#elif ((__CFI_LDBL_MANT_DIG__ == 64 || __CFI_LDBL_MANT_DIG__ == 53) \
+       && __CFI_LDBL_MIN_EXP__ == -16381 \
+       && __CFI_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 96-bit encoding on m68k; Fortran assigns it kind 10.  */
-#elif (LDBL_MANT_DIG == 64 \
-       && LDBL_MIN_EXP == -16382 \
-       && LDBL_MAX_EXP == 16384)
+#elif (__CFI_LDBL_MANT_DIG__ == 64 \
+       && __CFI_LDBL_MIN_EXP__ == -16382 \
+       && __CFI_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)
+#elif (__CFI_LDBL_MANT_DIG__ == 113 \
+       && __CFI_LDBL_MIN_EXP__ == -16381 \
+       && __CFI_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)
+#elif (__CFI_LDBL_MANT_DIG__ == 106 \
+       && __CFI_LDBL_MIN_EXP__ == -968 \
+       && __CFI_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

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [committed] Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h (was: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h)
  2021-09-17 14:10               ` [committed] Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h (was: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h) Tobias Burnus
@ 2021-09-18  4:51                 ` Gerald Pfeifer
  0 siblings, 0 replies; 26+ messages in thread
From: Gerald Pfeifer @ 2021-09-18  4:51 UTC (permalink / raw)
  To: Tobias Burnus
  Cc: Jakub Jelinek, Sandra Loosemore, Andreas Schwab, Andreas Tobler,
	fortran, gcc-patches

On Fri, 17 Sep 2021, Tobias Burnus wrote:
> I have now committed the attached patch as r12-3621. It includes the
> patch by Sandra
> https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579372.html
> (approved 3 days ago) plus adding the "== 53" similar to above.

Thank you, Tobias; thank you, everyone!

> Hopefully, we can now close this issue.

My nightly tester passed the build and is currently running the
testsuite, so looks good.

Gerald

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2021-09-18  4:51 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19  2:57 [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Sandra Loosemore
2021-09-03  2:05 ` PING " Sandra Loosemore
2021-09-06 19:29 ` Tobias Burnus
2021-09-10 15:39 ` Andreas Schwab
2021-09-13  7:51   ` Tobias Burnus
2021-09-13 15:56 ` Gerald Pfeifer
2021-09-13 16:32   ` Tobias Burnus
2021-09-13 16:51     ` Jakub Jelinek
2021-09-13 16:59       ` Sandra Loosemore
2021-09-13 17:07         ` Tobias Burnus
2021-09-13 17:20           ` Jakub Jelinek
2021-09-14  3:39           ` Sandra Loosemore
2021-09-14  7:39             ` Tobias Burnus
2021-09-14 16:34             ` Gerald Pfeifer
2021-09-14 14:50     ` Gerald Pfeifer
2021-09-14 15:16       ` Tobias Burnus
2021-09-14 15:17       ` Andreas Schwab
2021-09-14 15:23         ` Jakub Jelinek
2021-09-14 15:30           ` Andreas Schwab
2021-09-15  1:05             ` Joseph Myers
2021-09-14 19:27           ` Gerald Pfeifer
2021-09-17  6:03             ` Gerald Pfeifer
2021-09-17 14:10               ` [committed] Fortran: Prefer GCC internal macros to float.h in ISO_Fortran_binding.h (was: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h) Tobias Burnus
2021-09-18  4:51                 ` Gerald Pfeifer
2021-09-13 17:39   ` [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Andreas Schwab
2021-09-13 18:07   ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).