public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/3] [PR libfortran/101305] Bind(C): Fix kind/size mappings
@ 2021-07-13 21:28 Sandra Loosemore
  2021-07-13 21:28 ` [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h Sandra Loosemore
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-13 21:28 UTC (permalink / raw)
  To: gcc-patches, fortran

This set of patches is for PR libfortran/101305, about bugs in
ISO_Fortran_binding.h's type kind/size encodings, and also incorrect
kind/size mappings in CFI_establish.  For instance,
ISO_Fortran_binding.h had hard-wired encodings that ptrdiff_t and long
are 8 bytes that are clearly incorrect on a 32-bit target, and other
encodings like CFI_type_int_fast8_t and CFI_type_long_double were
incorrect on some 64-bit targets too.  So part of this patch involves
using sizeof in the CFI_type_* macro definitions, instead of literal
constants.

Another difficulty is that the 2018 Fortran standard requires that the
CFI_type_* macros for C types not supported by the Fortran processor
have negative values.  Tobias contributed some scripting to check for
that; now ISO_Fortran_binding.h is generated at build time from
fragments in the libgfortran source directory.

The remaining parts of the patch fix up related bugs in CFI_establish
for types whose size isn't directly encoded in the corresponding
CFI_type_* macro, and adjust include paths for ISO_Fortran_binding.h
in the test suite.

Jose has posted a patch that fixes some additional bugs in type/size encodings
in descriptors passed to and from C:

https://gcc.gnu.org/pipermail/fortran/2021-June/056154.html

and there remains a messy bug (PR fortran/100917) relating to
ambiguity in handling long double on some targets -- specifically, on
x86_64 targets that have both 80-bit long doubles with a storage size
of 16 and a true 128-bit floating-point format, the GFC descriptor
representation can't tell them apart.

I tested these patches on i686-pc-linux-gnu with both -m32 and -m64
multilibs.

Sandra Loosemore (3):
  [PR libfortran/101305] Bind(C): Fix type encodings in
    ISO_Fortran_binding.h
  [PR libfortran/101305] Bind(C): Correct sizes of some types in
    CFI_establish
  [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran
    testsuite

 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c  |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c  |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c  |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c  |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c  |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c  |   2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c  |   2 +-
 .../gfortran.dg/bind_c_array_params_3_aux.c        |   2 +-
 .../iso_fortran_binding_uint8_array_driver.c       |   2 +-
 gcc/testsuite/gfortran.dg/pr93524.c                |   2 +-
 libgfortran/ISO_Fortran_binding-1-tmpl.h           | 196 ++++++++++++++++++++
 libgfortran/ISO_Fortran_binding-2-tmpl.h           |  42 +++++
 libgfortran/ISO_Fortran_binding-3-tmpl.h           |   5 +
 libgfortran/ISO_Fortran_binding.h                  | 206 ---------------------
 libgfortran/Makefile.am                            |  15 +-
 libgfortran/Makefile.in                            |  16 +-
 libgfortran/mk-kinds-h.sh                          |  25 ++-
 libgfortran/runtime/ISO_Fortran_binding.c          |  21 ++-
 25 files changed, 319 insertions(+), 241 deletions(-)
 create mode 100644 libgfortran/ISO_Fortran_binding-1-tmpl.h
 create mode 100644 libgfortran/ISO_Fortran_binding-2-tmpl.h
 create mode 100644 libgfortran/ISO_Fortran_binding-3-tmpl.h
 delete mode 100644 libgfortran/ISO_Fortran_binding.h

-- 
2.8.1


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

* [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h
  2021-07-13 21:28 [PATCH 0/3] [PR libfortran/101305] Bind(C): Fix kind/size mappings Sandra Loosemore
@ 2021-07-13 21:28 ` Sandra Loosemore
  2021-07-21 10:03   ` Tobias Burnus
  2021-07-13 21:28 ` [PATCH 2/3] [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish Sandra Loosemore
  2021-07-13 21:28 ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Sandra Loosemore
  2 siblings, 1 reply; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-13 21:28 UTC (permalink / raw)
  To: gcc-patches, fortran

ISO_Fortran_binding.h had many incorrect hardwired kind encodings in
the definitions of the CFI_type_* macros.  Additionally, not all
targets support all the defined type encodings, and the Fortran
standard requires those macros to have a negative value.

This patch changes ISO_Fortran_binding.h to use sizeof instead of
hard-coded sizes, and assembles it from fragments that reflect the
set of types supported by the target.

2021-07-13  Sandra Loosemore  <sandra@codesourcery.com>
	    Tobias Burnus  <tobias@codesourcery.com>

libgfortran/
	PR libfortran/101305
	* ISO_Fortran_binding.h: Fix hard-coded sizes and split into...
	* ISO_Fortran_binding-1-tmpl.h: New file.
	* ISO_Fortran_binding-2-tmpl.h: New file.
	* ISO_Fortran_binding-3-tmpl.h: New file.
	* Makefile.am: Add rule for generating ISO_Fortran_binding.h.
	Adjust pathnames to that file.
	* Makefile.in: Regenerated.
	* mk-kinds-h.sh: New file.
	* runtime/ISO_Fortran_binding.c: Fix include path.
---
 libgfortran/ISO_Fortran_binding-1-tmpl.h  | 196 ++++++++++++++++++++++++++++
 libgfortran/ISO_Fortran_binding-2-tmpl.h  |  42 ++++++
 libgfortran/ISO_Fortran_binding-3-tmpl.h  |   5 +
 libgfortran/ISO_Fortran_binding.h         | 206 ------------------------------
 libgfortran/Makefile.am                   |  15 ++-
 libgfortran/Makefile.in                   |  16 ++-
 libgfortran/mk-kinds-h.sh                 |  25 +++-
 libgfortran/runtime/ISO_Fortran_binding.c |   2 +-
 8 files changed, 292 insertions(+), 215 deletions(-)
 create mode 100644 libgfortran/ISO_Fortran_binding-1-tmpl.h
 create mode 100644 libgfortran/ISO_Fortran_binding-2-tmpl.h
 create mode 100644 libgfortran/ISO_Fortran_binding-3-tmpl.h
 delete mode 100644 libgfortran/ISO_Fortran_binding.h

diff --git a/libgfortran/ISO_Fortran_binding-1-tmpl.h b/libgfortran/ISO_Fortran_binding-1-tmpl.h
new file mode 100644
index 0000000..dde7c3d
--- /dev/null
+++ b/libgfortran/ISO_Fortran_binding-1-tmpl.h
@@ -0,0 +1,196 @@
+/* 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.
+   CFI_INVALID_STRIDE should be defined in the standard because they are useful to the implementation of the functions.
+ */
+#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
new file mode 100644
index 0000000..ad88f8b
--- /dev/null
+++ b/libgfortran/ISO_Fortran_binding-2-tmpl.h
@@ -0,0 +1,42 @@
+#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
new file mode 100644
index 0000000..aec4288
--- /dev/null
+++ b/libgfortran/ISO_Fortran_binding-3-tmpl.h
@@ -0,0 +1,5 @@
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ISO_FORTRAN_BINDING_H */
diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h
deleted file mode 100644
index 6c4d461..0000000
--- a/libgfortran/ISO_Fortran_binding.h
+++ /dev/null
@@ -1,206 +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.
-   CFI_INVALID_STRIDE should be defined in the standard because they are useful to the implementation of the functions.
- */
-#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 kind = 10, which has byte size of 64 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 + (1 << CFI_type_kind_shift))
-#define CFI_type_short (CFI_type_Integer + (2 << CFI_type_kind_shift))
-#define CFI_type_int (CFI_type_Integer + (4 << CFI_type_kind_shift))
-#define CFI_type_long (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_long_long (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_size_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_int8_t (CFI_type_Integer + (1 << CFI_type_kind_shift))
-#define CFI_type_int16_t (CFI_type_Integer + (2 << CFI_type_kind_shift))
-#define CFI_type_int32_t (CFI_type_Integer + (4 << CFI_type_kind_shift))
-#define CFI_type_int64_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_int_least8_t (CFI_type_Integer + (1 << CFI_type_kind_shift))
-#define CFI_type_int_least16_t (CFI_type_Integer + (2 << CFI_type_kind_shift))
-#define CFI_type_int_least32_t (CFI_type_Integer + (4 << CFI_type_kind_shift))
-#define CFI_type_int_least64_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_int_fast8_t (CFI_type_Integer + (1 << CFI_type_kind_shift))
-#define CFI_type_int_fast16_t (CFI_type_Integer + (2 << CFI_type_kind_shift))
-#define CFI_type_int_fast32_t (CFI_type_Integer + (4 << CFI_type_kind_shift))
-#define CFI_type_int_fast64_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_intmax_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_intptr_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#define CFI_type_ptrdiff_t (CFI_type_Integer + (8 << CFI_type_kind_shift))
-#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))
-#define CFI_type_Bool (CFI_type_Logical + (1 << CFI_type_kind_shift))
-#define CFI_type_float (CFI_type_Real + (4 << CFI_type_kind_shift))
-#define CFI_type_double (CFI_type_Real + (8 << CFI_type_kind_shift))
-#define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift))
-#define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift))
-#define CFI_type_float_Complex (CFI_type_Complex + (4 << CFI_type_kind_shift))
-#define CFI_type_double_Complex (CFI_type_Complex + (8 << CFI_type_kind_shift))
-#define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift))
-#define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* ISO_FORTRAN_BINDING_H */
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 61bf05d..3546a3f 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -30,8 +30,8 @@ version_arg =
 version_dep =
 endif
 
-gfor_c_HEADERS = $(srcdir)/ISO_Fortran_binding.h
-gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
+gfor_c_HEADERS = ISO_Fortran_binding.h
+gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
 
 LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \
 	    $(lt_host_flags)
@@ -817,6 +817,7 @@ gfor_built_src= $(i_all_c) $(i_any_c) $(i_count_c) $(i_maxloc0_c) \
     $(i_pow_c) $(i_pack_c) $(i_unpack_c) $(i_matmulavx128_c) \
     $(i_spread_c) selected_int_kind.inc selected_real_kind.inc kinds.h \
     $(i_cshift0_c) kinds.inc c99_protos.inc fpu-target.h fpu-target.inc \
+    ISO_Fortran_binding.h \
     $(i_cshift1a_c) $(i_maxloc0s_c) $(i_minloc0s_c) $(i_maxloc1s_c) \
     $(i_minloc1s_c) $(i_maxloc2s_c) $(i_minloc2s_c) $(i_maxvals_c) \
     $(i_maxval0s_c) $(i_minval0s_c) $(i_maxval1s_c) $(i_minval1s_c) \
@@ -1075,6 +1076,16 @@ fpu-target.inc: fpu-target.h $(srcdir)/libgfortran.h
 	grep '^#define GFC_FPE_' < $(top_srcdir)/../gcc/fortran/libgfortran.h > $@ || true
 	grep '^#define GFC_FPE_' < $(srcdir)/libgfortran.h >> $@ || true
 
+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
+	-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 >> $@
+
 ## A 'normal' build shouldn't need to regenerate these
 ## so we only include them in maintainer mode
 
diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in
index 3d043aa..a7d8e11 100644
--- a/libgfortran/Makefile.in
+++ b/libgfortran/Makefile.in
@@ -698,6 +698,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -723,8 +724,8 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
 @LIBGFOR_USE_SYMVER_FALSE@version_dep = 
 @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 = $(srcdir)/ISO_Fortran_binding.h
-gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include
+gfor_c_HEADERS = ISO_Fortran_binding.h
+gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include
 LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \
 	    $(lt_host_flags)
 
@@ -1381,6 +1382,7 @@ gfor_built_src = $(i_all_c) $(i_any_c) $(i_count_c) $(i_maxloc0_c) \
     $(i_pow_c) $(i_pack_c) $(i_unpack_c) $(i_matmulavx128_c) \
     $(i_spread_c) selected_int_kind.inc selected_real_kind.inc kinds.h \
     $(i_cshift0_c) kinds.inc c99_protos.inc fpu-target.h fpu-target.inc \
+    ISO_Fortran_binding.h \
     $(i_cshift1a_c) $(i_maxloc0s_c) $(i_minloc0s_c) $(i_maxloc1s_c) \
     $(i_minloc1s_c) $(i_maxloc2s_c) $(i_minloc2s_c) $(i_maxvals_c) \
     $(i_maxval0s_c) $(i_minval0s_c) $(i_maxval1s_c) $(i_minval1s_c) \
@@ -7040,6 +7042,16 @@ fpu-target.inc: fpu-target.h $(srcdir)/libgfortran.h
 	grep '^#define GFC_FPE_' < $(top_srcdir)/../gcc/fortran/libgfortran.h > $@ || true
 	grep '^#define GFC_FPE_' < $(srcdir)/libgfortran.h >> $@ || true
 
+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
+	-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 >> $@
+
 @MAINTAINER_MODE_TRUE@$(i_all_c): m4/all.m4 $(I_M4_DEPS2)
 @MAINTAINER_MODE_TRUE@	$(M4) -Dfile=$@ -I$(srcdir)/m4 all.m4 > $@
 
diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh
index 2496190..f4244f0 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}"
-    echo "#define HAVE_GFC_INTEGER_${k}"
+    echo "#define HAVE_GFC_LOGICAL_${k} 1"
+    echo "#define HAVE_GFC_INTEGER_${k} 1"
     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}"
-    echo "#define HAVE_GFC_COMPLEX_${k}"
+    echo "#define HAVE_GFC_REAL_${k} 1"
+    echo "#define HAVE_GFC_COMPLEX_${k} 1"
     echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}"
     echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}"
     if [ "x$suffix" = "x" ]; then
@@ -114,6 +114,23 @@ 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.
diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
index 73fb4c4..28fa9f5 100644
--- a/libgfortran/runtime/ISO_Fortran_binding.c
+++ b/libgfortran/runtime/ISO_Fortran_binding.c
@@ -27,7 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgfortran.h"
-#include <ISO_Fortran_binding.h>
+#include "ISO_Fortran_binding.h"
 #include <string.h>
 
 extern void cfi_desc_to_gfc_desc (gfc_array_void *, CFI_cdesc_t **);
-- 
2.8.1


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

* [PATCH 2/3] [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish
  2021-07-13 21:28 [PATCH 0/3] [PR libfortran/101305] Bind(C): Fix kind/size mappings Sandra Loosemore
  2021-07-13 21:28 ` [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h Sandra Loosemore
@ 2021-07-13 21:28 ` Sandra Loosemore
  2021-07-21  9:48   ` Tobias Burnus
  2021-07-13 21:28 ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Sandra Loosemore
  2 siblings, 1 reply; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-13 21:28 UTC (permalink / raw)
  To: gcc-patches, fortran

CFI_establish was failing to set the default elem_len correctly for
CFI_type_cptr, CFI_type_cfunptr, CFI_type_long_double, and
CFI_type_long_double_Complex.

2021-07-13  Sandra Loosemore  <sandra@codesourcery.com>

libgfortran/
	PR libfortran/101305
	* runtime/ISO_Fortran_binding.c (CFI_establish): Special-case
	CFI_type_cptr and CFI_type_cfunptr.  Correct size of long double
	on targets where it has kind 10.
---
 libgfortran/runtime/ISO_Fortran_binding.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
index 28fa9f5..6b5f26c 100644
--- a/libgfortran/runtime/ISO_Fortran_binding.c
+++ b/libgfortran/runtime/ISO_Fortran_binding.c
@@ -341,9 +341,13 @@ int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,
 
   dv->base_addr = base_addr;
 
-  if (type == CFI_type_char || type == CFI_type_ucs4_char ||
-      type == CFI_type_struct || type == CFI_type_other)
+  if (type == CFI_type_char || type == CFI_type_ucs4_char
+      || type == CFI_type_struct || type == CFI_type_other)
     dv->elem_len = elem_len;
+  else if (type == CFI_type_cptr)
+    dv->elem_len = sizeof (void *);
+  else if (type == CFI_type_cfunptr)
+    dv->elem_len = sizeof (void (*)(void));
   else
     {
       /* base_type describes the intrinsic type with kind parameter. */
@@ -351,16 +355,13 @@ int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,
       /* base_type_size is the size in bytes of the variable as given by its
        * kind parameter. */
       size_t base_type_size = (type - base_type) >> CFI_type_kind_shift;
-      /* Kind types 10 have a size of 64 bytes. */
+      /* Kind type 10 maps onto the 80-bit long double encoding on x86.
+	 Note that this has different storage size for -m32 than -m64.  */
       if (base_type_size == 10)
-	{
-	  base_type_size = 64;
-	}
+	base_type_size = sizeof (long double);
       /* Complex numbers are twice the size of their real counterparts. */
       if (base_type == CFI_type_Complex)
-	{
-	  base_type_size *= 2;
-	}
+	base_type_size *= 2;
       dv->elem_len = base_type_size;
     }
 
-- 
2.8.1


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

* [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-13 21:28 [PATCH 0/3] [PR libfortran/101305] Bind(C): Fix kind/size mappings Sandra Loosemore
  2021-07-13 21:28 ` [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h Sandra Loosemore
  2021-07-13 21:28 ` [PATCH 2/3] [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish Sandra Loosemore
@ 2021-07-13 21:28 ` Sandra Loosemore
  2021-07-21 10:17   ` Tobias Burnus
  2021-08-04  9:00   ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Andreas Schwab
  2 siblings, 2 replies; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-13 21:28 UTC (permalink / raw)
  To: gcc-patches, fortran

ISO_Fortran_binding.h is now generated in the libgfortran build
directory where it is on the default include path.  Adjust includes in
the gfortran testsuite not to include an explicit path pointing at the
source directory.

2021-07-13  Sandra Loosemore  <sandra@codesourcery.com>

gcc/testsuite/
	PR libfortran/101305
	* gfortran.dg/ISO_Fortran_binding_1.c: Adjust include path.
	* gfortran.dg/ISO_Fortran_binding_10.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_11.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_12.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_15.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_16.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_17.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_18.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_3.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_5.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_6.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_7.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_8.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_9.c: Likewise.
	* gfortran.dg/bind_c_array_params_3_aux.c: Likewise.
	* gfortran.dg/iso_fortran_binding_uint8_array_driver.c: Likewise.
	* gfortran.dg/pr93524.c: Likewise.
---
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c                  | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c                 | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c                  | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c                  | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c                  | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c                  | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c                  | 2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c                  | 2 +-
 gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c              | 2 +-
 gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c | 2 +-
 gcc/testsuite/gfortran.dg/pr93524.c                                | 2 +-
 17 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
index a571459..9da5d85 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
@@ -1,6 +1,6 @@
 /* Test F2008 18.5: ISO_Fortran_binding.h functions.  */
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
index 9f06e2d..c3954e4 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de> */
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
index ac17690..c2d4e11 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
@@ -5,7 +5,7 @@ Contributed by Reinhold Bader  <Bader@lrz.de>#include <stdio.h> */
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdio.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 typedef struct
 {
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
index 279d9f6..078c5de 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
@@ -2,7 +2,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de>  */
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
index f5c83c7..622f2de 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
@@ -4,7 +4,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 // Prototype for Fortran functions
 extern void Fsub(CFI_cdesc_t *);
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
index cdee0b8..50b92ec 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
@@ -1,6 +1,6 @@
 /* Test the fix for PR92142. */
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
index 14dfcc9..b0893cc 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
@@ -2,7 +2,7 @@
 
 #include <stdio.h>
 #include <assert.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 void Csub(const CFI_cdesc_t *, size_t, CFI_index_t invalid);
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
index eef5cc6..ef40134 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 
 extern int do_loop(CFI_cdesc_t* array);
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
index a9f64cd..9f35b0d 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
@@ -1,4 +1,4 @@
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
index f8bdb27..116f548 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
@@ -4,7 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 typedef struct {
   int i;
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
index 9ef46ce..704b27c 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
@@ -4,7 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 #define DEBUG 0
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
index d68428f..26b4ab5 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de> */
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
index dc80cd3..a0d1bdc 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de> */
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 #include <stdio.h>
 
 float Cxgl[] = { 1.1, 2.3, 5.1, 4.2 };
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
index cb5b91d..632604f 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Gilles Gouaillardet  <gilles@rist.or.jp> */
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 #include <stdlib.h>
 
 int cdesc_c(CFI_cdesc_t* x, long *expected)
diff --git a/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c b/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
index 07d1a03..5176d8b 100644
--- a/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
+++ b/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
@@ -5,7 +5,7 @@
 #include <errno.h>
 #include <stdio.h>
 
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 void arr_set_c(CFI_cdesc_t*);
 
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
index 79b8a14..bfd567b 100644
--- a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
@@ -1,7 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 extern void fsub(CFI_cdesc_t *);
 
diff --git a/gcc/testsuite/gfortran.dg/pr93524.c b/gcc/testsuite/gfortran.dg/pr93524.c
index 24e5e09..ba40d00 100644
--- a/gcc/testsuite/gfortran.dg/pr93524.c
+++ b/gcc/testsuite/gfortran.dg/pr93524.c
@@ -2,7 +2,7 @@
    sm incorrectly for dimensions > 2.  */
 
 #include <stdlib.h>  // For size_t
-#include "../../../libgfortran/ISO_Fortran_binding.h"
+#include "ISO_Fortran_binding.h"
 
 void my_fortran_sub_1 (CFI_cdesc_t *dv); 
 void my_fortran_sub_2 (CFI_cdesc_t *dv); 
-- 
2.8.1


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

* Re: [PATCH 2/3] [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish
  2021-07-13 21:28 ` [PATCH 2/3] [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish Sandra Loosemore
@ 2021-07-21  9:48   ` Tobias Burnus
  0 siblings, 0 replies; 19+ messages in thread
From: Tobias Burnus @ 2021-07-21  9:48 UTC (permalink / raw)
  To: Sandra Loosemore, gcc-patches, fortran

On 13.07.21 23:28, Sandra Loosemore wrote:
> CFI_establish was failing to set the default elem_len correctly for
> CFI_type_cptr, CFI_type_cfunptr, CFI_type_long_double, and
> CFI_type_long_double_Complex.

LGTM – thanks for the patch!

Tobias

> 2021-07-13  Sandra Loosemore  <sandra@codesourcery.com>
>
> libgfortran/
>       PR libfortran/101305
>       * runtime/ISO_Fortran_binding.c (CFI_establish): Special-case
>       CFI_type_cptr and CFI_type_cfunptr.  Correct size of long double
>       on targets where it has kind 10.
> ---
>   libgfortran/runtime/ISO_Fortran_binding.c | 19 ++++++++++---------
>   1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
> index 28fa9f5..6b5f26c 100644
> --- a/libgfortran/runtime/ISO_Fortran_binding.c
> +++ b/libgfortran/runtime/ISO_Fortran_binding.c
> @@ -341,9 +341,13 @@ int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,
>
>     dv->base_addr = base_addr;
>
> -  if (type == CFI_type_char || type == CFI_type_ucs4_char ||
> -      type == CFI_type_struct || type == CFI_type_other)
> +  if (type == CFI_type_char || type == CFI_type_ucs4_char
> +      || type == CFI_type_struct || type == CFI_type_other)
>       dv->elem_len = elem_len;
> +  else if (type == CFI_type_cptr)
> +    dv->elem_len = sizeof (void *);
> +  else if (type == CFI_type_cfunptr)
> +    dv->elem_len = sizeof (void (*)(void));
>     else
>       {
>         /* base_type describes the intrinsic type with kind parameter. */
> @@ -351,16 +355,13 @@ int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,
>         /* base_type_size is the size in bytes of the variable as given by its
>          * kind parameter. */
>         size_t base_type_size = (type - base_type) >> CFI_type_kind_shift;
> -      /* Kind types 10 have a size of 64 bytes. */
> +      /* Kind type 10 maps onto the 80-bit long double encoding on x86.
> +      Note that this has different storage size for -m32 than -m64.  */
>         if (base_type_size == 10)
> -     {
> -       base_type_size = 64;
> -     }
> +     base_type_size = sizeof (long double);
>         /* Complex numbers are twice the size of their real counterparts. */
>         if (base_type == CFI_type_Complex)
> -     {
> -       base_type_size *= 2;
> -     }
> +     base_type_size *= 2;
>         dv->elem_len = base_type_size;
>       }
>
-----------------
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] 19+ messages in thread

* Re: [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h
  2021-07-13 21:28 ` [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h Sandra Loosemore
@ 2021-07-21 10:03   ` Tobias Burnus
  0 siblings, 0 replies; 19+ messages in thread
From: Tobias Burnus @ 2021-07-21 10:03 UTC (permalink / raw)
  To: Sandra Loosemore, gcc-patches, fortran

On 13.07.21 23:28, Sandra Loosemore wrote:

> ISO_Fortran_binding.h had many incorrect hardwired kind encodings in
> the definitions of the CFI_type_* macros.  Additionally, not all
> targets support all the defined type encodings, and the Fortran
> standard requires those macros to have a negative value.
>
> This patch changes ISO_Fortran_binding.h to use sizeof instead of
> hard-coded sizes, and assembles it from fragments that reflect the
> set of types supported by the target.
>
> 2021-07-13  Sandra Loosemore<sandra@codesourcery.com>
>           Tobias Burnus<tobias@codesourcery.com>
>
> libgfortran/
>       PR libfortran/101305
>       * ISO_Fortran_binding.h: Fix hard-coded sizes and split into...
>       * ISO_Fortran_binding-1-tmpl.h: New file.
>       * ISO_Fortran_binding-2-tmpl.h: New file.
>       * ISO_Fortran_binding-3-tmpl.h: New file.
>       * Makefile.am: Add rule for generating ISO_Fortran_binding.h.
>       Adjust pathnames to that file.
>       * Makefile.in: Regenerated.
>       * mk-kinds-h.sh: New file.
>       * runtime/ISO_Fortran_binding.c: Fix include path.
LGTM – except for the following remark regarding a preexisting comment.

> --- /dev/null
> +++ b/libgfortran/ISO_Fortran_binding-1-tmpl.h
> +/* Error codes.
> +   CFI_INVALID_STRIDE should be defined in the standard because they are useful to the implementation of the functions.
> + */

The standard permits: "Error conditions other than those listed in this
subclause should be indicated by error codes different from the values
of the macros named in this subclause."

I personally do not like current (preexisting) the wording in the
comment – and CFI_FAILURE is also not listed, which is also not part
of Fortran standard. I think some wording along the following is
be more appropriate:
"Note that CFI_FAILURE and CFI_INVALID_STRIDE 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

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] 19+ messages in thread

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-13 21:28 ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Sandra Loosemore
@ 2021-07-21 10:17   ` Tobias Burnus
  2021-07-23 14:15     ` Tobias Burnus
  2021-08-04  9:00   ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Andreas Schwab
  1 sibling, 1 reply; 19+ messages in thread
From: Tobias Burnus @ 2021-07-21 10:17 UTC (permalink / raw)
  To: Sandra Loosemore, gcc-patches, fortran

On 13.07.21 23:28, Sandra Loosemore wrote:
> ISO_Fortran_binding.h is now generated in the libgfortran build
> directory where it is on the default include path.  Adjust includes in
> the gfortran testsuite not to include an explicit path pointing at the
> source directory.
...
> -#include "../../../libgfortran/ISO_Fortran_binding.h"
> +#include "ISO_Fortran_binding.h"

Unfortunately, that does not help.

When running the testsuite in the build directory (cd $BUILD/gcc),
I get:

testsuite/gfortran.dg/pr93524.c:5:10: fatal error: ISO_Fortran_binding.h: No such file or directory

I wonder whether we need to do the same as with libgomp and libstdc++,
namely adding a libgfortran/testsuite/ to handle this.

In any case, compiling with '-v' shows all currently
searched include paths are the same for -m32 and -m64,
which is will pick up the wrong one for -m32. I tried it
by using the command line used when running in tree
   make check-fortran RUNTESTFLAGS="dg.exp=pr93524.f90 --target_board=unix\{-m32,\}"

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] 19+ messages in thread

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-21 10:17   ` Tobias Burnus
@ 2021-07-23 14:15     ` Tobias Burnus
  2021-07-23 20:43       ` Sandra Loosemore
  0 siblings, 1 reply; 19+ messages in thread
From: Tobias Burnus @ 2021-07-23 14:15 UTC (permalink / raw)
  To: Sandra Loosemore, gcc-patches, fortran

Hi Sandra,

On 21.07.21 12:17, Tobias Burnus wrote:
> On 13.07.21 23:28, Sandra Loosemore wrote:
>> ISO_Fortran_binding.h is now generated in the libgfortran build
>> directory where it is on the default include path.  Adjust includes in
>> the gfortran testsuite not to include an explicit path pointing at the
>> source directory.
> ...
>> -#include "../../../libgfortran/ISO_Fortran_binding.h"
>> +#include "ISO_Fortran_binding.h"
> Unfortunately, that does not help.

It seems as if the following works in the *.exp file:

# Flags for finding libgfortran ISO*.h files.
if [info exists TOOL_OPTIONS] {
    set specpath [get_multilibs ${TOOL_OPTIONS}]
} else {
    set specpath [get_multilibs]
}
set options "-I $specpath/libgfortran/"

I am not sure whether that should/can be added into
   gfortran.dg/dg.exp
or whether we only want to do this in
   ts29113/ts29113.exp
alias
   c-interop/interop.exp
   f18-c-interop/interop.exp
   ...

That seems to work fine with -m32 and -m64.

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] 19+ messages in thread

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-23 14:15     ` Tobias Burnus
@ 2021-07-23 20:43       ` Sandra Loosemore
  2021-07-26  9:45         ` Tobias Burnus
  0 siblings, 1 reply; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-23 20:43 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran

On 7/23/21 8:15 AM, Tobias Burnus wrote:
> Hi Sandra,
> 
> On 21.07.21 12:17, Tobias Burnus wrote:
>> On 13.07.21 23:28, Sandra Loosemore wrote:
>>> ISO_Fortran_binding.h is now generated in the libgfortran build
>>> directory where it is on the default include path.  Adjust includes in
>>> the gfortran testsuite not to include an explicit path pointing at the
>>> source directory.
>> ...
>>> -#include "../../../libgfortran/ISO_Fortran_binding.h"
>>> +#include "ISO_Fortran_binding.h"
>> Unfortunately, that does not help.
> 
> It seems as if the following works in the *.exp file:
> 
> # Flags for finding libgfortran ISO*.h files.
> if [info exists TOOL_OPTIONS] {
>     set specpath [get_multilibs ${TOOL_OPTIONS}]
> } else {
>     set specpath [get_multilibs]
> }
> set options "-I $specpath/libgfortran/"
> 
> I am not sure whether that should/can be added into
>    gfortran.dg/dg.exp
> or whether we only want to do this in
>    ts29113/ts29113.exp
> alias
>    c-interop/interop.exp
>    f18-c-interop/interop.exp
>    ...
> 
> That seems to work fine with -m32 and -m64.

Well, given that the original patch in this thread was for tests outside 
the ts29113 testsuite, any fix has to go someplace where those tests 
would pick it up too.

I'm not seeing the include path failures Tobias is seeing, so I can't 
confirm his change fixes them, either.  When I do "make check-fortran" 
in my build tree, it seems to be finding the include files because of 
there being a pile of -B options added to the gfortran command line.  I 
don't know where those are coming from, or why this isn't working for 
Tobias.  :-S

-Sandra


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

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-23 20:43       ` Sandra Loosemore
@ 2021-07-26  9:45         ` Tobias Burnus
  2021-07-26 20:13           ` Sandra Loosemore
  0 siblings, 1 reply; 19+ messages in thread
From: Tobias Burnus @ 2021-07-26  9:45 UTC (permalink / raw)
  To: Sandra Loosemore, gcc-patches, fortran

Hi Sandra,

On 23.07.21 22:43, Sandra Loosemore wrote:
> On 7/23/21 8:15 AM, Tobias Burnus wrote:
>> On 21.07.21 12:17, Tobias Burnus wrote:
>>> On 13.07.21 23:28, Sandra Loosemore wrote:
>>>> ISO_Fortran_binding.h is now generated in the libgfortran build
>>>> directory where it is on the default include path.  Adjust includes
>>>> [...]
>>> Unfortunately, that does not help.
>> It seems as if the following works in the *.exp file:
>> [...]
> I'm not seeing the include path failures Tobias is seeing, [...] why
> this isn't working for Tobias.  :-S

I also do not have any idea – I did bootstrap before into an empty directory
and I don't think I had other patches applied.

I have no idea why it did not work – nor why it now works. I did now (again?):

* Reset all patches + re-apply your three patches
* Bootstrap into an empty directory with
   $ ..../configure --prefix=... --enable-multiarch --enable-languages=c,c++,fortran,lto,objc
   $ make -j12 && make install
   $ cd gcc
   $ make check-fortran RUNTESTFLAGS="dg.exp=ISO_Fortran_binding_1.f90 --target_board=unix\{,-m32\}"

and now I got:
                 === gfortran Summary for unix ===
# of expected passes            12
                 === gfortran Summary for unix/-m32 ===
# of expected passes            12

Thus, it (mostly) works.
(I also did a more complete 'make check-fortran' run.)

  * * *

I did say that it mostly works because of:

$ find x86_64-pc-linux-gnu/ -name ISO_Fortran_binding.h
x86_64-pc-linux-gnu/libgfortran/ISO_Fortran_binding.h
x86_64-pc-linux-gnu/32/libgfortran/ISO_Fortran_binding.h

And when looking at the -B lines, I see for the '' alias '-m64' run:
-B.../build/gcc/testsuite/gfortran/../../
-B.../build/x86_64-pc-linux-gnu/./libgfortran/
-B.../build/x86_64-pc-linux-gnu/./libgfortran/.libs
-B.../build/x86_64-pc-linux-gnu/./libquadmath/.libs

which is fine (second line ensures the ISO*.h file is found.)

But for -m32, I see:

-B.../build/gcc/testsuite/gfortran/../../
-B.../build/x86_64-pc-linux-gnu/./libgfortran/
-B.../build/x86_64-pc-linux-gnu/32/libgfortran/.libs
-B.../build/x86_64-pc-linux-gnu/32/libquadmath/.libs

That also works, but it uses again the same directory for ISO*.h,
such that the -m64 header file is used instead of the -m32 one.

  * * *

I am not sure whether it really matters – the differences between
the header files is (on x86-64-gnu-linux):

-#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))
+#define CFI_type_int128_t -2
+#define CFI_type_int_least128_t -2
+#define CFI_type_int_fast128_t -2

There might be larger differences on other multi-arch systems, but at least
for x86-64, it seems to be harmless. (-2 = not available).

For instance, there might be an issue on Windows. (I keep forgetting what
sizeof(long) is with -m64 – is is the same as sizeof(int) as with -m32?
Or is it 64bit with -m64?)

  * * *

Thus, I am puzzled why it failed before and not longer. But given that it
works now:

LGTM, thanks for the patch and sorry for the confusion!

Tobias

PS: Still, it would be nice if the proper multi-lib ISO*.h could be found;
while it usually does not matter, it could do so in some cases.

-----------------
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] 19+ messages in thread

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-26  9:45         ` Tobias Burnus
@ 2021-07-26 20:13           ` Sandra Loosemore
  2021-07-28  4:36             ` Sandra Loosemore
  0 siblings, 1 reply; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-26 20:13 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran

On 7/26/21 3:45 AM, Tobias Burnus wrote:
> 
> [snip]
> 
> I did say that it mostly works because of:
> 
> $ find x86_64-pc-linux-gnu/ -name ISO_Fortran_binding.h
> x86_64-pc-linux-gnu/libgfortran/ISO_Fortran_binding.h
> x86_64-pc-linux-gnu/32/libgfortran/ISO_Fortran_binding.h
> 
> And when looking at the -B lines, I see for the '' alias '-m64' run:
> -B.../build/gcc/testsuite/gfortran/../../
> -B.../build/x86_64-pc-linux-gnu/./libgfortran/
> -B.../build/x86_64-pc-linux-gnu/./libgfortran/.libs
> -B.../build/x86_64-pc-linux-gnu/./libquadmath/.libs
> 
> which is fine (second line ensures the ISO*.h file is found.)
> 
> But for -m32, I see:
> 
> -B.../build/gcc/testsuite/gfortran/../../
> -B.../build/x86_64-pc-linux-gnu/./libgfortran/
> -B.../build/x86_64-pc-linux-gnu/32/libgfortran/.libs
> -B.../build/x86_64-pc-linux-gnu/32/libquadmath/.libs
> 
> That also works, but it uses again the same directory for ISO*.h,
> such that the -m64 header file is used instead of the -m32 one.

I did some more experiments and I see that too.  :-S  It's finding a .h 
file, but not the right one.  :-(

> PS: Still, it would be nice if the proper multi-lib ISO*.h could be found;
> while it usually does not matter, it could do so in some cases.

I think I ought to fix this now instead of just sweeping it under the 
rug.  The suggestion you made previously to add

> # Flags for finding libgfortran ISO*.h files.
> if [info exists TOOL_OPTIONS] {
>    set specpath [get_multilibs ${TOOL_OPTIONS}]
> } else {
>    set specpath [get_multilibs]
> }
> set options "-I $specpath/libgfortran/"

to the .exp files looks consistent with what I see elsewhere for adding 
things to the include path, so I will give it a try and see how it works.

-Sandra

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

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-26 20:13           ` Sandra Loosemore
@ 2021-07-28  4:36             ` Sandra Loosemore
  2021-07-28 11:22               ` [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite) Tobias Burnus
  0 siblings, 1 reply; 19+ messages in thread
From: Sandra Loosemore @ 2021-07-28  4:36 UTC (permalink / raw)
  To: Tobias Burnus, gcc-patches, fortran

On 7/26/21 2:13 PM, Sandra Loosemore wrote:
> On 7/26/21 3:45 AM, Tobias Burnus wrote:
>>
>> [snip]
>>
>> PS: Still, it would be nice if the proper multi-lib ISO*.h could be 
>> found;
>> while it usually does not matter, it could do so in some cases.
> 
> I think I ought to fix this now instead of just sweeping it under the 
> rug.  The suggestion you made previously to add
> 
>> # Flags for finding libgfortran ISO*.h files.
>> if [info exists TOOL_OPTIONS] {
>>    set specpath [get_multilibs ${TOOL_OPTIONS}]
>> } else {
>>    set specpath [get_multilibs]
>> }
>> set options "-I $specpath/libgfortran/"
> 
> to the .exp files looks consistent with what I see elsewhere for adding 
> things to the include path, so I will give it a try and see how it works.

Unfortunately, I could not get this to work.  For installed-tree 
testing, this resulted in diagnostics about a nonexistent directory on 
the include path.  In my i686-pc-linux-gnu build I was having other 
problems when I tried build-tree testing using

make check-gfortran RUNTESTFLAGS="--target-board=localhost/m64"

or similar variants of --target-board (it seemed to be ignoring all the 
xfails?) so I did not think that could be the way people who normally 
test in the build tree can be doing it.  And when I tried a recipe like

make check-gfortran RUNTESTFLAGS="ts29113.exp --tool_opts='-m64'"

it found the ISO_Fortran_binding.h via the correct /64-specific path via 
a -B option, same as for installed-tree testing.

Since the patch was already approved without additional hacks to include 
file paths, I went ahead and pushed it as-is.  If somebody can provide 
me with an exact recipe for reproducing failures to find the include 
file, I'll take another stab at it, but TBH this is far from my area of 
expertise.  :-(

BTW, I can't find any documentation for what get_multilibs is supposed 
to do.  It seems to be part of Dejagnu itself rather than the gcc test 
support?

-Sandra

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

* [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite)
  2021-07-28  4:36             ` Sandra Loosemore
@ 2021-07-28 11:22               ` Tobias Burnus
  2021-07-28 22:56                 ` Jakub Jelinek
  0 siblings, 1 reply; 19+ messages in thread
From: Tobias Burnus @ 2021-07-28 11:22 UTC (permalink / raw)
  To: Sandra Loosemore, gcc-patches, fortran

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

Hi Sandra, hi all,

On 28.07.21 06:36, Sandra Loosemore wrote:
> On 7/26/21 2:13 PM, Sandra Loosemore wrote:
>> On 7/26/21 3:45 AM, Tobias Burnus wrote:
>>> PS: Still, it would be nice if the proper multi-lib ISO*.h could be
>>> found;

(Example for x86-64-gnu-linux with 32bit and 64bit support)

Namely,
   x86_64-pc-linux-gnu/libgfortran/ISO_Fortran_binding.h
   x86_64-pc-linux-gnu/32/libgfortran/ISO_Fortran_binding.h
exist and they are different.

GCC finds the correct header, when running:
   make check-fortran RUNTESTFLAGS="--target_board=unix\{-m32\}"
which runs gfortran with:
   -B.../x86_64-pc-linux-gnu/32/libgfortran/

Likewise, with "-m32" replaced by "-m64" or "",
it works and gfortran is run with
   -B.../x86_64-pc-linux-gnu/./libgfortran/


But when running both at the same time, i.e.
   make check-fortran RUNTESTFLAGS="--target_board=unix\{,-m32\}"
(note the ',' before '-m32'), gfortran is run for
both "" (= -m64) and "-m32" with:
   -B.../x86_64-pc-linux-gnu/./libgfortran/
That's fine for -m64 but for -m32 it finds the wrong
ISO_Fortran_binding.h  file.


Solution:
Add a "-I" with the proper path to find the right *.h file.
'strace' confirms that the -I include path is searched before the
path provided by "-B".

[Note: I only did in-tree testing with that patch so far.]

Comments to the attached patch? Does it look OK?


  * * *

> Unfortunately, I could not get this to work.

I think the attached version does work :-)

> For installed-tree testing, this resulted in diagnostics about a
> nonexistent directory on the include path.  In my i686-pc-linux-gnu
> build I was having other problems when I tried build-tree testing using
>
> make check-gfortran RUNTESTFLAGS="--target-board=localhost/m64"

I have an x86-64-gnu-linux build and there I use
"--target_board=unix\{,-m32\}",
which seems to work fine and runs it first with "" (= -m64) and then
with -m32.
(See above.)

I also do not see any issues with xfailing.

> BTW, I can't find any documentation for what get_multilibs is supposed
> to do.  It seems to be part of Dejagnu itself rather than the gcc test
> support?

Yes, but the documentation is, well, short:
https://www.gnu.org/software/dejagnu/manual/get_005fmultilibs-procedure.html

In the DejaGNU source code, there is a better description (comment before the function):
Cf. https://git.savannah.gnu.org/gitweb/?p=dejagnu.git;a=blob;f=lib/libgloss.exp;;hb=HEAD#l389

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: dg-ISO-find.diff --]
[-- Type: text/x-patch, Size: 1417 bytes --]

gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305]

gcc/testsuite/
	PR libfortran/101305
	* gfortran.dg/dg.exp: Add '-I <get_multilibs>/libgfortran'
	compile flag.

diff --git a/gcc/testsuite/gfortran.dg/dg.exp b/gcc/testsuite/gfortran.dg/dg.exp
index 06689813d07..cb48ed3e7fb 100644
--- a/gcc/testsuite/gfortran.dg/dg.exp
+++ b/gcc/testsuite/gfortran.dg/dg.exp
@@ -28,6 +28,17 @@ if ![info exists DEFAULT_FFLAGS] then {
 # Initialize `dg'.
 dg-init
 
+# Flags for finding libgfortran ISO*.h files.
+if [info exists TOOL_OPTIONS] {
+   set specpath [get_multilibs ${TOOL_OPTIONS}]
+} else {
+   set specpath [get_multilibs]
+}
+set include_options "-I$specpath/libgfortran"
+if [file exists $specpath/libgfortran ] {
+    set include_options "-I$specpath/libgfortran" 
+}
+
 global gfortran_test_path
 global gfortran_aux_module_flags
 set gfortran_test_path $srcdir/$subdir
@@ -55,10 +66,10 @@ proc dg-compile-aux-modules { args } {
 
 # Main loop.
 gfortran-dg-runtest [lsort \
-       [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ] ] "" $DEFAULT_FFLAGS
+       [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ] ] "" "$include_options $DEFAULT_FFLAGS"
 
 gfortran-dg-runtest [lsort \
-       [glob -nocomplain $srcdir/$subdir/g77/*.\[fF\] ] ] "" $DEFAULT_FFLAGS
+       [glob -nocomplain $srcdir/$subdir/g77/*.\[fF\] ] ] "" "$include_options $DEFAULT_FFLAGS"
 
 
 # All done.

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

* Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite)
  2021-07-28 11:22               ` [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite) Tobias Burnus
@ 2021-07-28 22:56                 ` Jakub Jelinek
  2021-07-29  7:09                   ` Jakub Jelinek
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Jelinek @ 2021-07-28 22:56 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Sandra Loosemore, gcc-patches, fortran

On Wed, Jul 28, 2021 at 01:22:53PM +0200, Tobias Burnus wrote:
> gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305]
> 
> gcc/testsuite/
> 	PR libfortran/101305
> 	* gfortran.dg/dg.exp: Add '-I <get_multilibs>/libgfortran'
> 	compile flag.

Wouldn't it be better to do that in gcc/testsuite/lib/gfortran.exp
to GFORTRAN_UNDER_TEST there next to
-B$specpath/libgfortran/ ?
So that we don't add it for the installed gfortran testing - there
we want to test what installed gfortran will do,
and will affect also libgomp testing.

	Jakub


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

* Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite)
  2021-07-28 22:56                 ` Jakub Jelinek
@ 2021-07-29  7:09                   ` Jakub Jelinek
  2021-07-29  9:51                     ` [Patch] testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660] (was: Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite)) Tobias Burnus
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Jelinek @ 2021-07-29  7:09 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Sandra Loosemore, gcc-patches, fortran

On Thu, Jul 29, 2021 at 12:56:32AM +0200, Jakub Jelinek wrote:
> On Wed, Jul 28, 2021 at 01:22:53PM +0200, Tobias Burnus wrote:
> > gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305]
> > 
> > gcc/testsuite/
> > 	PR libfortran/101305
> > 	* gfortran.dg/dg.exp: Add '-I <get_multilibs>/libgfortran'
> > 	compile flag.
> 
> Wouldn't it be better to do that in gcc/testsuite/lib/gfortran.exp
> to GFORTRAN_UNDER_TEST there next to
> -B$specpath/libgfortran/ ?
> So that we don't add it for the installed gfortran testing - there
> we want to test what installed gfortran will do,
> and will affect also libgomp testing.

Though, I guess we need that mostly for the C FE, so perhaps it needs to go
at the start of additional_flags=, whether TEST_ALWAYS_FLAGS is empty or
not.

	Jakub


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

* [Patch] testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660] (was: Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite))
  2021-07-29  7:09                   ` Jakub Jelinek
@ 2021-07-29  9:51                     ` Tobias Burnus
  2021-08-09 10:50                       ` committed – " Tobias Burnus
  0 siblings, 1 reply; 19+ messages in thread
From: Tobias Burnus @ 2021-07-29  9:51 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Sandra Loosemore, gcc-patches, fortran

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

On 29.07.21 09:09, Jakub Jelinek wrote:
> On Thu, Jul 29, 2021 at 12:56:32AM +0200, Jakub Jelinek wrote:
>> On Wed, Jul 28, 2021 at 01:22:53PM +0200, Tobias Burnus wrote:
>>> gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305]
>> Wouldn't it be better to do that in gcc/testsuite/lib/gfortran.exp
>> to GFORTRAN_UNDER_TEST there next to
>> -B$specpath/libgfortran/ ?

I guess so – and that's what I did. However, I had to ensure that it
gets reset otherwise it picks up the wrong header in multilib runs; this
also affects the -B$specpath/libgfortran bit, but I think that makes sense.

> Though, I guess we need that mostly for the C FE, so perhaps it needs to go
> at the start of additional_flags=, whether TEST_ALWAYS_FLAGS is empty or
> not.

For the main testsuite (gcc/testsuite/*fortran*/), I believe the patch
above is sufficient as everything runs through GFORTRAN_UNDER_TEST.

I am also inclined not to add flags to TEST_ALWAYS_FLAGS which then
might get applied to other/pure C/C++ tests.

Regarding libgomp: that one uses xgcc for the compilation. I don't
really see a need to use the Fortran array descriptor from a C program
in libgomp's testsuite. Thus, I am inclined to ignore libgomp.
Otherwise, as libgomp does not gfortran_init and handles libraries
separately, I think the code needs to be put into
libgomp.*fortran/fortran.exp.

Thoughts? Okay?

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: dg-ISO-find-v2.diff --]
[-- Type: text/x-patch, Size: 9069 bytes --]

testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660]

This patch adds -I$specdir/libgfortran to GFORTRAN_UNDER_TEST, when
set by proc gfortran_init. As the $specdir depends on the multilib
setting, it has to be re-set for a different multilib; hence, we track
whether a previous call to gfortran_init set that var or whether it
was set differently.

gcc/testsuite/
	PR libfortran/101305
	PR fortran/101660

	* lib/gfortran.exp (gfortran_init): Add -I $specdir/libgfortran to
	GFORTRAN_UNDER_TEST; update it when set by previous gfortran_init call.
	* gfortran.dg/ISO_Fortran_binding_1.c: Use <...> not "..." for
	ISO_Fortran_binding.h's #include.
	* gfortran.dg/ISO_Fortran_binding_10.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_11.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_12.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_15.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_16.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_17.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_18.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_3.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_5.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_6.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_7.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_8.c: Likewise.
	* gfortran.dg/ISO_Fortran_binding_9.c: Likewise.
	* gfortran.dg/PR94327.c: Likewise.
	* gfortran.dg/PR94331.c: Likewise.
	* gfortran.dg/bind_c_array_params_3_aux.c: Likewise.
	* gfortran.dg/iso_fortran_binding_uint8_array_driver.c: Likewise.
	* gfortran.dg/pr93524.c: Likewise.

diff --git a/gcc/testsuite/lib/gfortran.exp b/gcc/testsuite/lib/gfortran.exp
index 1e7da1110bc..cae6738b4b8 100644
--- a/gcc/testsuite/lib/gfortran.exp
+++ b/gcc/testsuite/lib/gfortran.exp
@@ -151,6 +151,7 @@ proc gfortran_init { args } {
     global gcc_warning_prefix
     global gcc_error_prefix
     global TEST_ALWAYS_FLAGS
+    global gfortran_init_set_GFORTRAN_UNDER_TEST
 
     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
     setenv LC_ALL C
@@ -166,7 +167,11 @@ proc gfortran_init { args } {
       setenv LANG C.ASCII
     }
 
-    if ![info exists GFORTRAN_UNDER_TEST] then {
+    # GFORTRAN_UNDER_TEST as set below contains $specpath, which depends on
+    # the used multilib config. Thus, its value may need to be reset;
+    # that's tracked via gfortran_init_set_GFORTRAN_UNDER_TEST.
+    if { ![info exists GFORTRAN_UNDER_TEST]
+	 || [info exists gfortran_init_set_GFORTRAN_UNDER_TEST] } then {
 	if [info exists TOOL_EXECUTABLE] {
 	    set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
 	} else {
@@ -178,7 +183,8 @@ proc gfortran_init { args } {
 		} else {
 		    set specpath [get_multilibs]
 		}
-		set GFORTRAN_UNDER_TEST [findfile $base_dir/../../gfortran "$base_dir/../../gfortran -B$base_dir/../../ -B$specpath/libgfortran/" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
+		set gfortran_init_set_GFORTRAN_UNDER_TEST 1
+		set GFORTRAN_UNDER_TEST [findfile $base_dir/../../gfortran "$base_dir/../../gfortran -B$base_dir/../../ -B$specpath/libgfortran/ -I$specpath/libgfortran" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
 	    }
 	}
     }
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
@@ -3 +3 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
@@ -8 +8 @@ Contributed by Reinhold Bader  <Bader@lrz.de>#include <stdio.h> */
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
@@ -7 +7 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
@@ -3 +3 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
@@ -3 +3 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
@@ -1 +1 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
@@ -7 +7 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
@@ -7 +7 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/PR94327.c b/gcc/testsuite/gfortran.dg/PR94327.c
--- a/gcc/testsuite/gfortran.dg/PR94327.c
+++ b/gcc/testsuite/gfortran.dg/PR94327.c
@@ -7 +7 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/PR94331.c b/gcc/testsuite/gfortran.dg/PR94331.c
--- a/gcc/testsuite/gfortran.dg/PR94331.c
+++ b/gcc/testsuite/gfortran.dg/PR94331.c
@@ -7 +7 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c b/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
--- a/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
+++ b/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
@@ -8 +8 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
--- a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
@@ -4 +4 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
diff --git a/gcc/testsuite/gfortran.dg/pr93524.c b/gcc/testsuite/gfortran.dg/pr93524.c
--- a/gcc/testsuite/gfortran.dg/pr93524.c
+++ b/gcc/testsuite/gfortran.dg/pr93524.c
@@ -5 +5 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>

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

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-07-13 21:28 ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Sandra Loosemore
  2021-07-21 10:17   ` Tobias Burnus
@ 2021-08-04  9:00   ` Andreas Schwab
  2021-08-09 10:52     ` Tobias Burnus
  1 sibling, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2021-08-04  9:00 UTC (permalink / raw)
  To: Sandra Loosemore; +Cc: gcc-patches, fortran

On Jul 13 2021, Sandra Loosemore wrote:

> diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
> index a571459..9da5d85 100644
> --- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
> +++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
> @@ -1,6 +1,6 @@
>  /* Test F2008 18.5: ISO_Fortran_binding.h functions.  */
>  
> -#include "../../../libgfortran/ISO_Fortran_binding.h"
> +#include "ISO_Fortran_binding.h"

Shouldn't that use <ISO_Fortran_binding.h> since that is an installed
header, not one that is supposed to be picked up from the current
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] 19+ messages in thread

* committed – Re: [Patch] testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660] (was: Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite))
  2021-07-29  9:51                     ` [Patch] testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660] (was: Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite)) Tobias Burnus
@ 2021-08-09 10:50                       ` Tobias Burnus
  0 siblings, 0 replies; 19+ messages in thread
From: Tobias Burnus @ 2021-08-09 10:50 UTC (permalink / raw)
  To: gcc-patches, fortran
  Cc: Sandra Loosemore, Mike Stump, Rainer Orth, Jakub Jelinek

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

Now committed as obvious as https://gcc.gnu.org/r12-2808-g527a1cf32c27a3fbeaf6be7596241570d864cc4c

Follow-up suggestions are welcome. To recap, it changes three things:

* In the testcases, update "..." to "<...>" for the include
* -I $specpath/libgfortran - to find the .h file in the build dir (for in-build-tree testing)
* Update GFORTRAN_UNDER_TEST

The first two are very obvious, the latter applies, when running DejaGNU with, e.g.,
--target_board=unix\{-m32,-m64\}".
Those two multilib configs use different libgfortran build dirs and, hence,
the $specpath/libgfortran differs (e.g. x86.../libgfortran + x86.../32/libgfortran).

That's fine, except that when gfortran_init sets GFORTRAN_UNDER_TEST. That only
happend when it was unset. That's fine, except for multilib test runs, it is not
updated when gfortran_init is called for the next multilib run. Thus, in that case
the previous settings are used. – For the discussion in this thread, this means the
wrong ISO_Fortran_binding.h is read.

Or in previous wording:

On 29.07.21 11:51, Tobias Burnus wrote:
> On 29.07.21 09:09, Jakub Jelinek wrote:
>> On Thu, Jul 29, 2021 at 12:56:32AM +0200, Jakub Jelinek wrote:
>>> On Wed, Jul 28, 2021 at 01:22:53PM +0200, Tobias Burnus wrote:
>>>> gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305]
>>> Wouldn't it be better to do that in gcc/testsuite/lib/gfortran.exp
>>> to GFORTRAN_UNDER_TEST there next to
>>> -B$specpath/libgfortran/ ?
>
> I guess so – and that's what I did. However, I had to ensure that it
> gets reset otherwise it picks up the wrong header in multilib runs;
> this also affects the -B$specpath/libgfortran bit, but I think that
> makes sense.
>
>> Though, I guess we need that mostly for the C FE, so perhaps it needs
>> to go
>> at the start of additional_flags=, whether TEST_ALWAYS_FLAGS is empty or
>> not.
>
> For the main testsuite (gcc/testsuite/*fortran*/), I believe the patch
> above is sufficient as everything runs through GFORTRAN_UNDER_TEST.
>
> I am also inclined not to add flags to TEST_ALWAYS_FLAGS which then
> might get applied to other/pure C/C++ tests.
>
> Regarding libgomp: that one uses xgcc for the compilation. I don't
> really see a need to use the Fortran array descriptor from a C program
> in libgomp's testsuite. Thus, I am inclined to ignore libgomp.
> Otherwise, as libgomp does not gfortran_init and handles libraries
> separately, I think the code needs to be put into
> libgomp.*fortran/fortran.exp.
>
> Thoughts? Okay?

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: 13687 bytes --]

commit 527a1cf32c27a3fbeaf6be7596241570d864cc4c
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Aug 9 12:35:23 2021 +0200

    testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660]
    
    This patch adds -I$specdir/libgfortran to GFORTRAN_UNDER_TEST, when
    set by proc gfortran_init. As the $specdir depends on the multilib
    setting, it has to be re-set for a different multilib; hence, we track
    whether a previous call to gfortran_init set that var or whether it
    was set differently.
    
    gcc/testsuite/
            PR libfortran/101305
            PR fortran/101660
    
            * lib/gfortran.exp (gfortran_init): Add -I $specdir/libgfortran to
            GFORTRAN_UNDER_TEST; update it when set by previous gfortran_init call.
            * gfortran.dg/ISO_Fortran_binding_1.c: Use <...> not "..." for
            ISO_Fortran_binding.h's #include.
            * gfortran.dg/ISO_Fortran_binding_10.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_11.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_12.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_15.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_16.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_17.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_18.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_3.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_5.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_6.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_7.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_8.c: Likewise.
            * gfortran.dg/ISO_Fortran_binding_9.c: Likewise.
            * gfortran.dg/PR94327.c: Likewise.
            * gfortran.dg/PR94331.c: Likewise.
            * gfortran.dg/bind_c_array_params_3_aux.c: Likewise.
            * gfortran.dg/iso_fortran_binding_uint8_array_driver.c: Likewise.
            * gfortran.dg/pr93524.c: Likewise.
---
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c              |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c             |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c              |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c              |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c              |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c              |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c              |  2 +-
 gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c              |  2 +-
 gcc/testsuite/gfortran.dg/PR94327.c                            |  2 +-
 gcc/testsuite/gfortran.dg/PR94331.c                            |  2 +-
 gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c          |  2 +-
 .../gfortran.dg/iso_fortran_binding_uint8_array_driver.c       |  2 +-
 gcc/testsuite/gfortran.dg/pr93524.c                            |  2 +-
 gcc/testsuite/lib/gfortran.exp                                 | 10 ++++++++--
 20 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
index bb56ca0e04b..d0d036ae779 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_1.c
@@ -1,6 +1,6 @@
 /* Test F2008 18.5: ISO_Fortran_binding.h functions.  */
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
index c3954e4e782..91222fff481 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de> */
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
index c2d4e11c9d3..e013011a380 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_11.c
@@ -5,7 +5,7 @@ Contributed by Reinhold Bader  <Bader@lrz.de>#include <stdio.h> */
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdio.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 typedef struct
 {
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
index 078c5de87d0..0a41576aa5e 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
@@ -2,7 +2,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de>  */
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
index 622f2de6ff3..fc70da4d133 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_15.c
@@ -4,7 +4,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 // Prototype for Fortran functions
 extern void Fsub(CFI_cdesc_t *);
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
index 50b92ec069c..915b6e7d568 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c
@@ -1,6 +1,6 @@
 /* Test the fix for PR92142. */
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
index b0893cc15e8..fa75268cd26 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_17.c
@@ -2,7 +2,7 @@
 
 #include <stdio.h>
 #include <assert.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 void Csub(const CFI_cdesc_t *, size_t, CFI_index_t invalid);
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
index ef40134fa3c..5a3952ca92e 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_18.c
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 
 extern int do_loop(CFI_cdesc_t* array);
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
index 9f35b0dcb80..33d1bc3c7e3 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_3.c
@@ -1,4 +1,4 @@
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
index 116f548ad99..b18a899ba26 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_5.c
@@ -4,7 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 typedef struct {
   int i;
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
index 704b27cb28a..c7981c5847a 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_6.c
@@ -4,7 +4,7 @@
 
 #include <stdio.h>
 #include <math.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 #define DEBUG 0
 
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
index 26b4ab5a015..8162451ca99 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_7.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de> */
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
index a0d1bdc8e83..d3dce3a3472 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_8.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Reinhold Bader  <Bader@lrz.de> */
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 #include <stdio.h>
 
 float Cxgl[] = { 1.1, 2.3, 5.1, 4.2 };
diff --git a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
index 632604f5ee8..cb170778642 100644
--- a/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
+++ b/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_9.c
@@ -2,7 +2,7 @@
 
 /* Contributed by Gilles Gouaillardet  <gilles@rist.or.jp> */
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 #include <stdlib.h>
 
 int cdesc_c(CFI_cdesc_t* x, long *expected)
diff --git a/gcc/testsuite/gfortran.dg/PR94327.c b/gcc/testsuite/gfortran.dg/PR94327.c
index 4ce408dbc39..9d226811f58 100644
--- a/gcc/testsuite/gfortran.dg/PR94327.c
+++ b/gcc/testsuite/gfortran.dg/PR94327.c
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 bool c_vrfy (const CFI_cdesc_t *restrict);
 
diff --git a/gcc/testsuite/gfortran.dg/PR94331.c b/gcc/testsuite/gfortran.dg/PR94331.c
index 2fbfe0e7144..df571c7583c 100644
--- a/gcc/testsuite/gfortran.dg/PR94331.c
+++ b/gcc/testsuite/gfortran.dg/PR94331.c
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 bool c_vrfy (const CFI_cdesc_t *restrict);
 
diff --git a/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c b/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
index 5176d8b5741..45941853928 100644
--- a/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
+++ b/gcc/testsuite/gfortran.dg/bind_c_array_params_3_aux.c
@@ -5,7 +5,7 @@
 #include <errno.h>
 #include <stdio.h>
 
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 void arr_set_c(CFI_cdesc_t*);
 
diff --git a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
index bfd567bba95..9c2b5fb721b 100644
--- a/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
+++ b/gcc/testsuite/gfortran.dg/iso_fortran_binding_uint8_array_driver.c
@@ -1,7 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <inttypes.h>
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 extern void fsub(CFI_cdesc_t *);
 
diff --git a/gcc/testsuite/gfortran.dg/pr93524.c b/gcc/testsuite/gfortran.dg/pr93524.c
index ba40d007bfb..8a6c06677f2 100644
--- a/gcc/testsuite/gfortran.dg/pr93524.c
+++ b/gcc/testsuite/gfortran.dg/pr93524.c
@@ -2,7 +2,7 @@
    sm incorrectly for dimensions > 2.  */
 
 #include <stdlib.h>  // For size_t
-#include "ISO_Fortran_binding.h"
+#include <ISO_Fortran_binding.h>
 
 void my_fortran_sub_1 (CFI_cdesc_t *dv); 
 void my_fortran_sub_2 (CFI_cdesc_t *dv); 
diff --git a/gcc/testsuite/lib/gfortran.exp b/gcc/testsuite/lib/gfortran.exp
index 1e7da1110bc..cae6738b4b8 100644
--- a/gcc/testsuite/lib/gfortran.exp
+++ b/gcc/testsuite/lib/gfortran.exp
@@ -151,6 +151,7 @@ proc gfortran_init { args } {
     global gcc_warning_prefix
     global gcc_error_prefix
     global TEST_ALWAYS_FLAGS
+    global gfortran_init_set_GFORTRAN_UNDER_TEST
 
     # We set LC_ALL and LANG to C so that we get the same error messages as expected.
     setenv LC_ALL C
@@ -166,7 +167,11 @@ proc gfortran_init { args } {
       setenv LANG C.ASCII
     }
 
-    if ![info exists GFORTRAN_UNDER_TEST] then {
+    # GFORTRAN_UNDER_TEST as set below contains $specpath, which depends on
+    # the used multilib config. Thus, its value may need to be reset;
+    # that's tracked via gfortran_init_set_GFORTRAN_UNDER_TEST.
+    if { ![info exists GFORTRAN_UNDER_TEST]
+	 || [info exists gfortran_init_set_GFORTRAN_UNDER_TEST] } then {
 	if [info exists TOOL_EXECUTABLE] {
 	    set GFORTRAN_UNDER_TEST $TOOL_EXECUTABLE
 	} else {
@@ -178,7 +183,8 @@ proc gfortran_init { args } {
 		} else {
 		    set specpath [get_multilibs]
 		}
-		set GFORTRAN_UNDER_TEST [findfile $base_dir/../../gfortran "$base_dir/../../gfortran -B$base_dir/../../ -B$specpath/libgfortran/" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
+		set gfortran_init_set_GFORTRAN_UNDER_TEST 1
+		set GFORTRAN_UNDER_TEST [findfile $base_dir/../../gfortran "$base_dir/../../gfortran -B$base_dir/../../ -B$specpath/libgfortran/ -I$specpath/libgfortran" [findfile $base_dir/gfortran "$base_dir/gfortran -B$base_dir/" [transform gfortran]]]
 	    }
 	}
     }

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

* Re: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite
  2021-08-04  9:00   ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Andreas Schwab
@ 2021-08-09 10:52     ` Tobias Burnus
  0 siblings, 0 replies; 19+ messages in thread
From: Tobias Burnus @ 2021-08-09 10:52 UTC (permalink / raw)
  To: Andreas Schwab, Sandra Loosemore; +Cc: gcc-patches, fortran

Hi Andreas,

On 04.08.21 11:00, Andreas Schwab wrote:
> On Jul 13 2021, Sandra Loosemore wrote:
>> -#include "../../../libgfortran/ISO_Fortran_binding.h"
>> +#include "ISO_Fortran_binding.h"
> Shouldn't that use <ISO_Fortran_binding.h> since that is an installed
> header, not one that is supposed to be picked up from the current
> directory?

Yes – thus, it was changed by my patch:
https://gcc.gnu.org/pipermail/gcc-patches/2021-August/576970.html

https://gcc.gnu.org/r12-2808-g527a1cf32c27a3fbeaf6be7596241570d864cc4c  <https://gcc.gnu.org/r12-2808-g527a1cf32c27a3fbeaf6be7596241570d864cc4c>

Thanks for keeping an eye on patches and reporting issues :-)

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] 19+ messages in thread

end of thread, other threads:[~2021-08-09 10:53 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 21:28 [PATCH 0/3] [PR libfortran/101305] Bind(C): Fix kind/size mappings Sandra Loosemore
2021-07-13 21:28 ` [PATCH 1/3] [PR libfortran/101305] Bind(C): Fix type encodings in ISO_Fortran_binding.h Sandra Loosemore
2021-07-21 10:03   ` Tobias Burnus
2021-07-13 21:28 ` [PATCH 2/3] [PR libfortran/101305] Bind(C): Correct sizes of some types in CFI_establish Sandra Loosemore
2021-07-21  9:48   ` Tobias Burnus
2021-07-13 21:28 ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Sandra Loosemore
2021-07-21 10:17   ` Tobias Burnus
2021-07-23 14:15     ` Tobias Burnus
2021-07-23 20:43       ` Sandra Loosemore
2021-07-26  9:45         ` Tobias Burnus
2021-07-26 20:13           ` Sandra Loosemore
2021-07-28  4:36             ` Sandra Loosemore
2021-07-28 11:22               ` [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite) Tobias Burnus
2021-07-28 22:56                 ` Jakub Jelinek
2021-07-29  7:09                   ` Jakub Jelinek
2021-07-29  9:51                     ` [Patch] testsuite/lib/gfortran.exp: Add -I for ISO*.h [PR101305, PR101660] (was: Re: [Patch] gfortran.dg/dg.exp: Add libgfortran as -I flag for ISO*.h [PR101305] (was: [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite)) Tobias Burnus
2021-08-09 10:50                       ` committed – " Tobias Burnus
2021-08-04  9:00   ` [PATCH 3/3] [PR libfortran/101305] Fix ISO_Fortran_binding.h paths in gfortran testsuite Andreas Schwab
2021-08-09 10:52     ` Tobias Burnus

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).