From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id B8D933861C72; Thu, 19 Aug 2021 02:57:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B8D933861C72 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: 4+Uj0L9mgJBQge+O1UydLsNUjFA23aICgfOg5rF77fbRcA0qC+kU+/r69F77C+3UL7u36yqem8 Oq6RmUz+FG6jUXueOBbedTOoGpJ8ag+YGPPmm3hKhv6Tlu4dep/XdQW2AQ8Jh8g0YXPZtoukgr MnSDcGCohgHp+Rj4zxkTNhX1iqya5QSgkFfmcm0Xsicpj6v5GcxSttiX8ajL0s7OVn3tIofMHg 63Q75b0LPOznDyUwRjo7Yziqh66RevOFiA0qYxdIwIDOV2h/488aIUlyOfbJjubX85tHxtWN2x +Jppd28tZHNlaD6p24jFskXB X-IronPort-AV: E=Sophos;i="5.84,333,1620720000"; d="h'?scan'208";a="64856050" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 18 Aug 2021 18:57:10 -0800 IronPort-SDR: zqRiXxqYLGG0pxX6Qb3fx+KmZNd6eAcVguOlOSlBdPFCTCZal5TccSIZTaHg003vuVZNjnBLFa PcqYWJP8kqgKNhVD6gh7e791Db7TGZ3T48n6N3eMI/7YDedBEZjMbAg0jIXautQ+xt8FE9pAmN x84wveyvF/aKw8vdmOUi9zi6A+WGOh4mCtOR4fsRsgTmawbRFKhiX+RpB8T54ulPadO3pHoEOt R+KoSfvCJmiA7rvXZJK8DIpEifkyXFxZYT+aYkAd5BcWdDv8B0r+nDdvQtx/IphV26mESCZK5b faw= To: "fortran@gcc.gnu.org" , "gcc-patches@gcc.gnu.org" CC: Tobias Burnus From: Sandra Loosemore Subject: [PATCH, Fortran] Revert to non-multilib-specific ISO_Fortran_binding.h Message-ID: Date: Wed, 18 Aug 2021 20:57:02 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------23C497F3FCAD942B79864B4B" Content-Language: en-US X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-04.mgc.mentorg.com (147.34.90.204) X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2021 02:57:21 -0000 --------------23C497F3FCAD942B79864B4B Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit This is a follow-up to commit fef67987cf502fe322e92ddce22eea7ac46b4d75: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=fef67987cf502fe322e92ddce22eea7ac46b4d75 I realized last week that having multilib-specific versions of ISO_Fortran_binding.h (generated by running the compiler to ask what kinds it supports) was still broken outside of the test support; the directory where it's being installed isn't on GCC's normal search path. It seemed to me that it was better to try to find some other solution for this problem than to venture down what appears to be a rat hole. I've come up with this patch to return to a single ISO_Fortran_binding.h file that uses preprocessor magic to identify the Fortran kind corresponding to the standard C long double type and the GCC extension types __float128 and int128_t. I haven't attempted to undo the follow-up patches that fixed in-tree testing; the static .h file is still copied to the build directory, and it can still be referenced with <> syntax during testing. Any complaints about either the overall strategy here, or the logic to infer the C type -> kind mapping? Or OK to commit? -Sandra --------------23C497F3FCAD942B79864B4B Content-Type: text/x-chdr; charset="UTF-8"; name="fix-iso-fortran-binding.h" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-iso-fortran-binding.h" commit bf52fcb46ee62ff2f7c552397d58914b934b130f Author: Sandra Loosemore Date: Fri Aug 13 17:46:19 2021 -0700 Fortran: Revert to non-multilib-specific ISO_Fortran_binding.h Commit fef67987cf502fe322e92ddce22eea7ac46b4d75 changed the libgfortran build process to generate multilib-specific versions of ISO_Fortran_binding.h from a template, by running gfortran to identify the values of the Fortran kind constants C_LONG_DOUBLE, C_FLOAT128, and C_INT128_T. This caused multiple problems with search paths, both for build-tree testing and installed-tree use, not all of which have been fixed. This patch reverts to a non-multilib-specific .h file that uses GCC's predefined preprocessor symbols to detect the supported types and map them to kind values in the same way as the Fortran front end. 2021-08-18 Sandra Loosemore libgfortran/ * ISO_Fortran_binding-1-tmpl.h: Deleted. * ISO_Fortran_binding-2-tmpl.h: Deleted. * ISO_Fortran_binding-3-tmpl.h: Deleted. * ISO_Fortran_binding.h: New file to replace the above. * Makefile.am (gfor_cdir): Remove MULTISUBDIR. (ISO_Fortran_binding.h): Simplify to just copy the file. * Makefile.in: Regenerated. * mk-kinds-h.sh: Revert pieces no longer needed for ISO_Fortran_binding.h. diff --git a/libgfortran/ISO_Fortran_binding-1-tmpl.h b/libgfortran/ISO_Fortran_binding-1-tmpl.h deleted file mode 100644 index 8852c99..0000000 --- a/libgfortran/ISO_Fortran_binding-1-tmpl.h +++ /dev/null @@ -1,196 +0,0 @@ -/* Declarations for ISO Fortran binding. - Copyright (C) 2018-2021 Free Software Foundation, Inc. - Contributed by Daniel Celis Garza - -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 -. */ - -#ifndef ISO_FORTRAN_BINDING_H -#define ISO_FORTRAN_BINDING_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include /* Standard ptrdiff_t tand size_t. */ -#include /* Integer types. */ - -/* Constants, defined as macros. */ -#define CFI_VERSION 1 -#define CFI_MAX_RANK 15 - -/* Attributes. */ -#define CFI_attribute_pointer 0 -#define CFI_attribute_allocatable 1 -#define CFI_attribute_other 2 - -/* Error codes. - Note that CFI_FAILURE and CFI_INVALID_STRIDE are specific to GCC - and not part of the Fortran standard */ -#define CFI_SUCCESS 0 -#define CFI_FAILURE 1 -#define CFI_ERROR_BASE_ADDR_NULL 2 -#define CFI_ERROR_BASE_ADDR_NOT_NULL 3 -#define CFI_INVALID_ELEM_LEN 4 -#define CFI_INVALID_RANK 5 -#define CFI_INVALID_TYPE 6 -#define CFI_INVALID_ATTRIBUTE 7 -#define CFI_INVALID_EXTENT 8 -#define CFI_INVALID_STRIDE 9 -#define CFI_INVALID_DESCRIPTOR 10 -#define CFI_ERROR_MEM_ALLOCATION 11 -#define CFI_ERROR_OUT_OF_BOUNDS 12 - -/* CFI type definitions. */ -typedef ptrdiff_t CFI_index_t; -typedef int8_t CFI_rank_t; -typedef int8_t CFI_attribute_t; -typedef int16_t CFI_type_t; - -/* CFI_dim_t. */ -typedef struct CFI_dim_t - { - CFI_index_t lower_bound; - CFI_index_t extent; - CFI_index_t sm; - } -CFI_dim_t; - -/* CFI_cdesc_t, C descriptors are cast to this structure as follows: - CFI_CDESC_T(CFI_MAX_RANK) foo; - CFI_cdesc_t * bar = (CFI_cdesc_t *) &foo; - */ -typedef struct CFI_cdesc_t - { - void *base_addr; - size_t elem_len; - int version; - CFI_rank_t rank; - CFI_attribute_t attribute; - CFI_type_t type; - CFI_dim_t dim[]; - } -CFI_cdesc_t; - -/* CFI_CDESC_T with an explicit type. */ -#define CFI_CDESC_TYPE_T(r, base_type) \ - struct { \ - base_type *base_addr; \ - size_t elem_len; \ - int version; \ - CFI_rank_t rank; \ - CFI_attribute_t attribute; \ - CFI_type_t type; \ - CFI_dim_t dim[r]; \ - } -#define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void) - -/* CFI function declarations. */ -extern void *CFI_address (const CFI_cdesc_t *, const CFI_index_t []); -extern int CFI_allocate (CFI_cdesc_t *, const CFI_index_t [], const CFI_index_t [], - size_t); -extern int CFI_deallocate (CFI_cdesc_t *); -extern int CFI_establish (CFI_cdesc_t *, void *, CFI_attribute_t, CFI_type_t, size_t, - CFI_rank_t, const CFI_index_t []); -extern int CFI_is_contiguous (const CFI_cdesc_t *); -extern int CFI_section (CFI_cdesc_t *, const CFI_cdesc_t *, const CFI_index_t [], - const CFI_index_t [], const CFI_index_t []); -extern int CFI_select_part (CFI_cdesc_t *, const CFI_cdesc_t *, size_t, size_t); -extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []); - -/* Types and kind numbers. Allows bitwise and to reveal the intrinsic type of a kind type. It also allows us to find the kind parameter by inverting the bit-shift equation. - CFI_type_kind_shift = 8 - CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 - CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 - CFI_type_example = CFI_intrinsic_type + (CFI_type_kind << CFI_type_kind_shift) - Defining the CFI_type_example. - CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 << CFI_type_kind_shift - ------------------------- - 1 0 0 0 0 0 0 0 0 0 0 0 + - CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 - ------------------------- - CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 - Finding the intrinsic type with the logical mask. - CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 & - CFI_type_mask = 0 0 0 0 1 1 1 1 1 1 1 1 - ------------------------- - CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 - Using the intrinsic type and kind shift to find the kind value of the type. - CFI_type_kind = (CFI_type_example - CFI_intrinsic_type) >> CFI_type_kind_shift - CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 - - CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 - ------------------------- - 1 0 0 0 0 0 0 0 0 0 0 0 >> CFI_type_kind_shift - ------------------------- - CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 - */ -#define CFI_type_mask 0xFF -#define CFI_type_kind_shift 8 - -/* Intrinsic types. Their kind number defines their storage size. */ -#define CFI_type_Integer 1 -#define CFI_type_Logical 2 -#define CFI_type_Real 3 -#define CFI_type_Complex 4 -#define CFI_type_Character 5 - -/* Types with no kind. */ -#define CFI_type_struct 6 -#define CFI_type_cptr 7 -#define CFI_type_cfunptr 8 -#define CFI_type_other -1 - -/* Types with kind parameter. - The kind parameter represents the type's byte size. The exception is - real kind = 10, which has byte size of 128 bits but 80 bit precision. - Complex variables are double the byte size of their real counterparts. - The ucs4_char matches wchar_t if sizeof (wchar_t) == 4. - */ -#define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift)) -#define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift)) - -/* C-Fortran Interoperability types. */ -#define CFI_type_signed_char (CFI_type_Integer + (sizeof (char) << CFI_type_kind_shift)) -#define CFI_type_short (CFI_type_Integer + (sizeof (short) << CFI_type_kind_shift)) -#define CFI_type_int (CFI_type_Integer + (sizeof (int) << CFI_type_kind_shift)) -#define CFI_type_long (CFI_type_Integer + (sizeof (long) << CFI_type_kind_shift)) -#define CFI_type_long_long (CFI_type_Integer + (sizeof (long long) << CFI_type_kind_shift)) -#define CFI_type_size_t (CFI_type_Integer + (sizeof (size_t) << CFI_type_kind_shift)) -#define CFI_type_int8_t (CFI_type_Integer + (sizeof (int8_t) << CFI_type_kind_shift)) -#define CFI_type_int16_t (CFI_type_Integer + (sizeof (int16_t) << CFI_type_kind_shift)) -#define CFI_type_int32_t (CFI_type_Integer + (sizeof (int32_t) << CFI_type_kind_shift)) -#define CFI_type_int64_t (CFI_type_Integer + (sizeof (int64_t) << CFI_type_kind_shift)) -#define CFI_type_int_least8_t (CFI_type_Integer + (sizeof (int_least8_t) << CFI_type_kind_shift)) -#define CFI_type_int_least16_t (CFI_type_Integer + (sizeof (int_least16_t) << CFI_type_kind_shift)) -#define CFI_type_int_least32_t (CFI_type_Integer + (sizeof (int_least32_t) << CFI_type_kind_shift)) -#define CFI_type_int_least64_t (CFI_type_Integer + (sizeof (int_least64_t) << CFI_type_kind_shift)) -#define CFI_type_int_fast8_t (CFI_type_Integer + (sizeof (int_fast8_t) << CFI_type_kind_shift)) -#define CFI_type_int_fast16_t (CFI_type_Integer + (sizeof (int_fast16_t) << CFI_type_kind_shift)) -#define CFI_type_int_fast32_t (CFI_type_Integer + (sizeof (int_fast32_t) << CFI_type_kind_shift)) -#define CFI_type_int_fast64_t (CFI_type_Integer + (sizeof (int_fast64_t) << CFI_type_kind_shift)) -#define CFI_type_intmax_t (CFI_type_Integer + (sizeof (intmax_t) << CFI_type_kind_shift)) -#define CFI_type_intptr_t (CFI_type_Integer + (sizeof (intptr_t) << CFI_type_kind_shift)) -#define CFI_type_ptrdiff_t (CFI_type_Integer + (sizeof (ptrdiff_t) << CFI_type_kind_shift)) -#define CFI_type_Bool (CFI_type_Logical + (sizeof (_Bool) << CFI_type_kind_shift)) -#define CFI_type_float (CFI_type_Real + (sizeof (float) << CFI_type_kind_shift)) -#define CFI_type_double (CFI_type_Real + (sizeof (double) << CFI_type_kind_shift)) -#define CFI_type_float_Complex (CFI_type_Complex + (sizeof (float) << CFI_type_kind_shift)) -#define CFI_type_double_Complex (CFI_type_Complex + (sizeof (double) << CFI_type_kind_shift)) diff --git a/libgfortran/ISO_Fortran_binding-2-tmpl.h b/libgfortran/ISO_Fortran_binding-2-tmpl.h deleted file mode 100644 index ad88f8b..0000000 --- a/libgfortran/ISO_Fortran_binding-2-tmpl.h +++ /dev/null @@ -1,42 +0,0 @@ -#include "config.h" -#include "kinds.inc" - -/* Note that -1 is used by CFI_type_other, hence, -2 is used for unavailable kinds. */ - -#if GFC_C_INT128_T_KIND == 16 -#define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) -#define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) -#define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) -#elif GFC_C_INT128_T_KIND < 0 -#define CFI_type_int128_t -2 -#define CFI_type_int_least128_t -2 -#define CFI_type_int_fast128_t -2 -#else -#error "Unexpected value for GFC_C_INT128_T_KIND" -#endif - -#if GFC_C_LONG_DOUBLE_KIND == 16 -#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift)) -#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift)) -#elif GFC_C_LONG_DOUBLE_KIND == 10 -#define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift)) -#define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift)) -#elif GFC_C_LONG_DOUBLE_KIND == 8 -#define CFI_type_long_double (CFI_type_Real + (8 << CFI_type_kind_shift)) -#define CFI_type_long_double_Complex (CFI_type_Complex + (8 << CFI_type_kind_shift)) -#elif GFC_C_LONG_DOUBLE_KIND < 0 -#define CFI_type_long_double -2 -#define CFI_type_long_double_Complex -2 -#else -#error "Unexpected value for GFC_C_LONG_DOUBLE_KIND" -#endif - -#if GFC_C_FLOAT128_KIND == 16 -#define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift)) -#define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift)) -#elif GFC_C_FLOAT128_KIND < 0 -#define CFI_type_float128 -2 -#define CFI_type_float128_Complex -2 -#else -#error "Unexpected value for GFC_C_FLOAT128_KIND" -#endif diff --git a/libgfortran/ISO_Fortran_binding-3-tmpl.h b/libgfortran/ISO_Fortran_binding-3-tmpl.h deleted file mode 100644 index aec4288..0000000 --- a/libgfortran/ISO_Fortran_binding-3-tmpl.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef __cplusplus -} -#endif - -#endif /* ISO_FORTRAN_BINDING_H */ diff --git a/libgfortran/ISO_Fortran_binding.h b/libgfortran/ISO_Fortran_binding.h new file mode 100644 index 0000000..686cc8b --- /dev/null +++ b/libgfortran/ISO_Fortran_binding.h @@ -0,0 +1,273 @@ +/* Declarations for ISO Fortran binding. + Copyright (C) 2018-2021 Free Software Foundation, Inc. + Contributed by Daniel Celis Garza + +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 +. */ + +#ifndef ISO_FORTRAN_BINDING_H +#define ISO_FORTRAN_BINDING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include /* Standard ptrdiff_t tand size_t. */ +#include /* Integer types. */ +#include /* Macros for floating-point type characteristics. */ + +/* Constants, defined as macros. */ +#define CFI_VERSION 1 +#define CFI_MAX_RANK 15 + +/* Attributes. */ +#define CFI_attribute_pointer 0 +#define CFI_attribute_allocatable 1 +#define CFI_attribute_other 2 + +/* Error codes. + Note that CFI_FAILURE and CFI_INVALID_STRIDE are specific to GCC + and not part of the Fortran standard */ +#define CFI_SUCCESS 0 +#define CFI_FAILURE 1 +#define CFI_ERROR_BASE_ADDR_NULL 2 +#define CFI_ERROR_BASE_ADDR_NOT_NULL 3 +#define CFI_INVALID_ELEM_LEN 4 +#define CFI_INVALID_RANK 5 +#define CFI_INVALID_TYPE 6 +#define CFI_INVALID_ATTRIBUTE 7 +#define CFI_INVALID_EXTENT 8 +#define CFI_INVALID_STRIDE 9 +#define CFI_INVALID_DESCRIPTOR 10 +#define CFI_ERROR_MEM_ALLOCATION 11 +#define CFI_ERROR_OUT_OF_BOUNDS 12 + +/* CFI type definitions. */ +typedef ptrdiff_t CFI_index_t; +typedef int8_t CFI_rank_t; +typedef int8_t CFI_attribute_t; +typedef int16_t CFI_type_t; + +/* CFI_dim_t. */ +typedef struct CFI_dim_t + { + CFI_index_t lower_bound; + CFI_index_t extent; + CFI_index_t sm; + } +CFI_dim_t; + +/* CFI_cdesc_t, C descriptors are cast to this structure as follows: + CFI_CDESC_T(CFI_MAX_RANK) foo; + CFI_cdesc_t * bar = (CFI_cdesc_t *) &foo; + */ +typedef struct CFI_cdesc_t + { + void *base_addr; + size_t elem_len; + int version; + CFI_rank_t rank; + CFI_attribute_t attribute; + CFI_type_t type; + CFI_dim_t dim[]; + } +CFI_cdesc_t; + +/* CFI_CDESC_T with an explicit type. */ +#define CFI_CDESC_TYPE_T(r, base_type) \ + struct { \ + base_type *base_addr; \ + size_t elem_len; \ + int version; \ + CFI_rank_t rank; \ + CFI_attribute_t attribute; \ + CFI_type_t type; \ + CFI_dim_t dim[r]; \ + } +#define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void) + +/* CFI function declarations. */ +extern void *CFI_address (const CFI_cdesc_t *, const CFI_index_t []); +extern int CFI_allocate (CFI_cdesc_t *, const CFI_index_t [], const CFI_index_t [], + size_t); +extern int CFI_deallocate (CFI_cdesc_t *); +extern int CFI_establish (CFI_cdesc_t *, void *, CFI_attribute_t, CFI_type_t, size_t, + CFI_rank_t, const CFI_index_t []); +extern int CFI_is_contiguous (const CFI_cdesc_t *); +extern int CFI_section (CFI_cdesc_t *, const CFI_cdesc_t *, const CFI_index_t [], + const CFI_index_t [], const CFI_index_t []); +extern int CFI_select_part (CFI_cdesc_t *, const CFI_cdesc_t *, size_t, size_t); +extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []); + +/* Types and kind numbers. Allows bitwise and to reveal the intrinsic type of a kind type. It also allows us to find the kind parameter by inverting the bit-shift equation. + CFI_type_kind_shift = 8 + CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 + CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 + CFI_type_example = CFI_intrinsic_type + (CFI_type_kind << CFI_type_kind_shift) + Defining the CFI_type_example. + CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 << CFI_type_kind_shift + ------------------------- + 1 0 0 0 0 0 0 0 0 0 0 0 + + CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 + ------------------------- + CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 + Finding the intrinsic type with the logical mask. + CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 & + CFI_type_mask = 0 0 0 0 1 1 1 1 1 1 1 1 + ------------------------- + CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 + Using the intrinsic type and kind shift to find the kind value of the type. + CFI_type_kind = (CFI_type_example - CFI_intrinsic_type) >> CFI_type_kind_shift + CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 - + CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0 + ------------------------- + 1 0 0 0 0 0 0 0 0 0 0 0 >> CFI_type_kind_shift + ------------------------- + CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 + */ +#define CFI_type_mask 0xFF +#define CFI_type_kind_shift 8 + +/* Intrinsic types. Their kind number defines their storage size. */ +#define CFI_type_Integer 1 +#define CFI_type_Logical 2 +#define CFI_type_Real 3 +#define CFI_type_Complex 4 +#define CFI_type_Character 5 + +/* Types with no kind. */ +#define CFI_type_struct 6 +#define CFI_type_cptr 7 +#define CFI_type_cfunptr 8 +#define CFI_type_other -1 + +/* Types with kind parameter. + The kind parameter represents the type's byte size. The exception is + real kind = 10, which has byte size of 128 bits but 80 bit precision. + Complex variables are double the byte size of their real counterparts. + The ucs4_char matches wchar_t if sizeof (wchar_t) == 4. + */ +#define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift)) +#define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift)) + +/* C-Fortran Interoperability types. */ +#define CFI_type_signed_char (CFI_type_Integer + (sizeof (char) << CFI_type_kind_shift)) +#define CFI_type_short (CFI_type_Integer + (sizeof (short) << CFI_type_kind_shift)) +#define CFI_type_int (CFI_type_Integer + (sizeof (int) << CFI_type_kind_shift)) +#define CFI_type_long (CFI_type_Integer + (sizeof (long) << CFI_type_kind_shift)) +#define CFI_type_long_long (CFI_type_Integer + (sizeof (long long) << CFI_type_kind_shift)) +#define CFI_type_size_t (CFI_type_Integer + (sizeof (size_t) << CFI_type_kind_shift)) +#define CFI_type_int8_t (CFI_type_Integer + (sizeof (int8_t) << CFI_type_kind_shift)) +#define CFI_type_int16_t (CFI_type_Integer + (sizeof (int16_t) << CFI_type_kind_shift)) +#define CFI_type_int32_t (CFI_type_Integer + (sizeof (int32_t) << CFI_type_kind_shift)) +#define CFI_type_int64_t (CFI_type_Integer + (sizeof (int64_t) << CFI_type_kind_shift)) +#define CFI_type_int_least8_t (CFI_type_Integer + (sizeof (int_least8_t) << CFI_type_kind_shift)) +#define CFI_type_int_least16_t (CFI_type_Integer + (sizeof (int_least16_t) << CFI_type_kind_shift)) +#define CFI_type_int_least32_t (CFI_type_Integer + (sizeof (int_least32_t) << CFI_type_kind_shift)) +#define CFI_type_int_least64_t (CFI_type_Integer + (sizeof (int_least64_t) << CFI_type_kind_shift)) +#define CFI_type_int_fast8_t (CFI_type_Integer + (sizeof (int_fast8_t) << CFI_type_kind_shift)) +#define CFI_type_int_fast16_t (CFI_type_Integer + (sizeof (int_fast16_t) << CFI_type_kind_shift)) +#define CFI_type_int_fast32_t (CFI_type_Integer + (sizeof (int_fast32_t) << CFI_type_kind_shift)) +#define CFI_type_int_fast64_t (CFI_type_Integer + (sizeof (int_fast64_t) << CFI_type_kind_shift)) +#define CFI_type_intmax_t (CFI_type_Integer + (sizeof (intmax_t) << CFI_type_kind_shift)) +#define CFI_type_intptr_t (CFI_type_Integer + (sizeof (intptr_t) << CFI_type_kind_shift)) +#define CFI_type_ptrdiff_t (CFI_type_Integer + (sizeof (ptrdiff_t) << CFI_type_kind_shift)) +#define CFI_type_Bool (CFI_type_Logical + (sizeof (_Bool) << CFI_type_kind_shift)) +#define CFI_type_float (CFI_type_Real + (sizeof (float) << CFI_type_kind_shift)) +#define CFI_type_double (CFI_type_Real + (sizeof (double) << CFI_type_kind_shift)) +#define CFI_type_float_Complex (CFI_type_Complex + (sizeof (float) << CFI_type_kind_shift)) +#define CFI_type_double_Complex (CFI_type_Complex + (sizeof (double) << CFI_type_kind_shift)) + +/* If GCC supports int128_t on this target, it predefines + __SIZEOF_INT128__ to 16. */ +#if defined(__SIZEOF_INT128__) +#if (__SIZEOF_INT128__ == 16) +#define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) +#define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) +#define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) +#else +#error "Can't determine kind of int128_t" +#endif +#else +#define CFI_type_int128_t -2 +#define CFI_type_int_least128_t -2 +#define CFI_type_int_fast128_t -2 +#endif + +/* The situation with long double support is more complicated; we need to + examine the type in more detail to figure out its kind. */ + +/* Long double is the same kind as double. */ +#if (LDBL_MANT_DIG == DBL_MANT_DIG \ + && LDBL_MIN_EXP == DBL_MIN_EXP \ + && LDBL_MAX_EXP == DBL_MAX_EXP) +#define CFI_type_long_double CFI_type_double +#define CFI_type_long_double_Complex CFI_type_double_Complex + +/* This is the 80-bit encoding on x86; Fortran assigns it kind 10. */ +#elif (LDBL_MANT_DIG == 64 \ + && LDBL_MIN_EXP == -16381 \ + && LDBL_MAX_EXP == 16384) +#define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift)) +#define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift)) + +/* This is the IEEE 128-bit encoding, same as float128. */ +#elif (LDBL_MANT_DIG == 113 \ + && LDBL_MIN_EXP == -16381 \ + && LDBL_MAX_EXP == 16384) +#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift)) +#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift)) + +/* This is the IBM128 encoding used on PowerPC; also assigned kind 16. */ +#elif (LDBL_MANT_DIG == 106 \ + && LDBL_MIN_EXP == -968 \ + && LDBL_MAX_EXP == 1024) +#define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift)) +#define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift)) +#define CFI_no_float128 1 + +/* It's a bug if we get here. If you've got a target that has some other + long double encoding, you need add something here for Fortran to + recognize it. */ +#else +#error "Can't determine kind of long double" +#endif + +/* Similarly for __float128. This always refers to the IEEE encoding + and not some other 128-bit representation, so if we already used + kind 16 for a non-IEEE representation, this one must be unsupported + in Fortran even if it's available in C. */ +#if (!defined (CFI_no_float128) \ + && defined(__FLT128_MANT_DIG__) && __FLT128_MANT_DIG__ == 113 \ + && defined(__FLT128_MIN_EXP__) && __FLT128_MIN_EXP__ == -16381 \ + && defined(__FLT128_MAX_EXP__) && __FLT128_MAX_EXP__ == 16384) +#define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift)) +#define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift)) +#else +#define CFI_type_float128 -2 +#define CFI_type_float128_Complex -2 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ISO_FORTRAN_BINDING_H */ diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index 8d10432..5874c0d 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -31,7 +31,7 @@ version_dep = endif gfor_c_HEADERS = ISO_Fortran_binding.h -gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include +gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \ $(lt_host_flags) @@ -1079,15 +1079,9 @@ fpu-target.inc: fpu-target.h $(srcdir)/libgfortran.h # Place ISO_Fortran_binding.h also under include/ in the build directory such # that it can be used for in-built-tree testsuite runs without interference of # other files in the build dir - like intrinsic .mod files or other .h files. -ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding-1-tmpl.h \ - $(srcdir)/ISO_Fortran_binding-2-tmpl.h \ - $(srcdir)/ISO_Fortran_binding-3-tmpl.h \ - kinds.inc +ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding.h -rm -f $@ - cp $(srcdir)/ISO_Fortran_binding-1-tmpl.h $@ - $(COMPILE) -E -dD $(srcdir)/ISO_Fortran_binding-2-tmpl.h \ - | grep '^#define CFI_type' >> $@ - cat $(srcdir)/ISO_Fortran_binding-3-tmpl.h >> $@ + cp $(srcdir)/ISO_Fortran_binding.h $@ $(MKDIR_P) include -rm -f include/ISO_Fortran_binding.h cp $@ include/ISO_Fortran_binding.h diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index afe1ed1..22a6942 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -724,7 +724,7 @@ gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER) @LIBGFOR_USE_SYMVER_GNU_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = $(srcdir)/gfortran.map @LIBGFOR_USE_SYMVER_SUN_TRUE@@LIBGFOR_USE_SYMVER_TRUE@version_dep = gfortran.map-sun gfor_c_HEADERS = ISO_Fortran_binding.h -gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/include +gfor_cdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)/include LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS)) \ $(lt_host_flags) @@ -7044,15 +7044,9 @@ fpu-target.inc: fpu-target.h $(srcdir)/libgfortran.h # Place ISO_Fortran_binding.h also under include/ in the build directory such # that it can be used for in-built-tree testsuite runs without interference of # other files in the build dir - like intrinsic .mod files or other .h files. -ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding-1-tmpl.h \ - $(srcdir)/ISO_Fortran_binding-2-tmpl.h \ - $(srcdir)/ISO_Fortran_binding-3-tmpl.h \ - kinds.inc +ISO_Fortran_binding.h: $(srcdir)/ISO_Fortran_binding.h -rm -f $@ - cp $(srcdir)/ISO_Fortran_binding-1-tmpl.h $@ - $(COMPILE) -E -dD $(srcdir)/ISO_Fortran_binding-2-tmpl.h \ - | grep '^#define CFI_type' >> $@ - cat $(srcdir)/ISO_Fortran_binding-3-tmpl.h >> $@ + cp $(srcdir)/ISO_Fortran_binding.h $@ $(MKDIR_P) include -rm -f include/ISO_Fortran_binding.h cp $@ include/ISO_Fortran_binding.h diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh index f4244f0..2496190 100755 --- a/libgfortran/mk-kinds-h.sh +++ b/libgfortran/mk-kinds-h.sh @@ -35,8 +35,8 @@ for k in $possible_integer_kinds; do echo "typedef ${prefix}int${s}_t GFC_INTEGER_${k};" echo "typedef ${prefix}uint${s}_t GFC_UINTEGER_${k};" echo "typedef GFC_INTEGER_${k} GFC_LOGICAL_${k};" - echo "#define HAVE_GFC_LOGICAL_${k} 1" - echo "#define HAVE_GFC_INTEGER_${k} 1" + echo "#define HAVE_GFC_LOGICAL_${k}" + echo "#define HAVE_GFC_INTEGER_${k}" echo "" fi rm -f tmp$$.* @@ -98,8 +98,8 @@ for k in $possible_real_kinds; do # Output the information we've gathered echo "typedef ${ctype} GFC_REAL_${k};" echo "typedef ${cplxtype} GFC_COMPLEX_${k};" - echo "#define HAVE_GFC_REAL_${k} 1" - echo "#define HAVE_GFC_COMPLEX_${k} 1" + echo "#define HAVE_GFC_REAL_${k}" + echo "#define HAVE_GFC_COMPLEX_${k}" echo "#define GFC_REAL_${k}_HUGE ${huge}${suffix}" echo "#define GFC_REAL_${k}_LITERAL_SUFFIX ${suffix}" if [ "x$suffix" = "x" ]; then @@ -114,23 +114,6 @@ for k in $possible_real_kinds; do rm -f tmp$$.* done -# For ISO_Fortran_binding.h -for k in "C_LONG_DOUBLE" "C_FLOAT128" "C_INT128_T"; do - fname="tmp$$.val" - echo "use iso_c_binding, only: $k; end" > tmp$$.f90 - if $compile -S -fdump-parse-tree tmp$$.f90 > "$fname"; then - kind=`grep "value:" "$fname" |grep value: | sed -e 's/.*value: *//'` - if [ "x$kind" = "x" ]; then - echo "ERROR: Failed to extract kind for $k" 1>&2 - exit 1 - fi - echo "#define GFC_${k}_KIND ${kind}" - else - echo "ERROR: Failed to extract kind for $k" 1>&2 - exit 1 - fi - rm -f tmp$$.* -done # After this, we include a header that can override some of the # autodetected settings. --------------23C497F3FCAD942B79864B4B--