From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1665) id 476473858D35; Wed, 22 Dec 2021 11:49:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 476473858D35 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: =?utf-8?q?Fran=E0=A4=A5=E0=A4=88ois-Xavier_Coudert?= To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6097] Fortran: allow __float128 on targets where long double is not REAL(KIND=10) X-Act-Checkin: gcc X-Git-Author: Francois-Xavier Coudert X-Git-Refname: refs/heads/master X-Git-Oldrev: 63eb073efbe6dfbf682b687dda2940ab027b474d X-Git-Newrev: 228173565eafbe34e44c1600c32e32a323eb5aab Message-Id: <20211222114937.476473858D35@sourceware.org> Date: Wed, 22 Dec 2021 11:49:37 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Dec 2021 11:49:37 -0000 https://gcc.gnu.org/g:228173565eafbe34e44c1600c32e32a323eb5aab commit r12-6097-g228173565eafbe34e44c1600c32e32a323eb5aab Author: Francois-Xavier Coudert Date: Wed Dec 22 12:46:07 2021 +0100 Fortran: allow __float128 on targets where long double is not REAL(KIND=10) The logic for detection of REAL(KIND=16) in kinds-override.h made assumptions: -- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined, then it is necessarily the "long double" type -- if real(kind=16) exists, then: * if HAVE_GFC_REAL_10, real(kind=16) is "__float128" * otherwise, real(kind=16) is "long double" This may not always be true. Take the aarch64-apple-darwin port, it has double == long double == binary64, and __float128 == binary128. We already have more fine-grained logic in the mk-kinds-h.sh script, where we actually check the Fortran kind corresponding to C’s long double. So let's use it, and emit the GFC_REAL_16_IS_FLOAT128 / GFC_REAL_16_IS_LONG_DOUBLE macros there. libgfortran/ChangeLog: * kinds-override.h: Move GFC_REAL_16_IS_* macros... * mk-kinds-h.sh: ... here. Diff: --- libgfortran/kinds-override.h | 23 ++++------------------- libgfortran/mk-kinds-h.sh | 6 +++++- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/libgfortran/kinds-override.h b/libgfortran/kinds-override.h index c9e874a3f38..5f7840b0c89 100644 --- a/libgfortran/kinds-override.h +++ b/libgfortran/kinds-override.h @@ -23,24 +23,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ -/* What are the C types corresponding to the real(kind=10) and - real(kind=16) types? We currently rely on the following assumptions: - -- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined, - then it is necessarily the "long double" type - -- if real(kind=16) exists, then: - * if HAVE_GFC_REAL_10, real(kind=16) is "__float128" - * otherwise, real(kind=16) is "long double" - To allow to change this in the future, we create the - GFC_REAL_16_IS_FLOAT128 macro that is used throughout libgfortran. */ - -#if defined(HAVE_GFC_REAL_16) -# if defined(HAVE_GFC_REAL_10) -# define GFC_REAL_16_IS_FLOAT128 -# if !defined(HAVE_FLOAT128) -# error "Where has __float128 gone?" -# endif -# else -# define GFC_REAL_16_IS_LONG_DOUBLE -# endif +/* Ensure that TFmode is available under. */ + +#if defined(GFC_REAL_16_IS_FLOAT128) && !defined(HAVE_FLOAT128) +# error "Where has __float128 gone?" #endif diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh index 249619061c6..572878ce891 100755 --- a/libgfortran/mk-kinds-h.sh +++ b/libgfortran/mk-kinds-h.sh @@ -64,15 +64,19 @@ for k in $possible_real_kinds; do case $k in 4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;; 8) ctype="double" ; cplxtype="complex double" ; suffix="" ;; + # If we have a REAL(KIND=10), it is always long double 10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;; - 16) if [ $long_double_kind -eq 10 ]; then + # If we have a REAL(KIND=16), it is either long double or __float128 + 16) if [ $long_double_kind -ne 16 ]; then ctype="__float128" cplxtype="_Complex float __attribute__((mode(TC)))" suffix="q" + echo "#define GFC_REAL_16_IS_FLOAT128" else ctype="long double" cplxtype="complex long double" suffix="l" + echo "#define GFC_REAL_16_IS_LONG_DOUBLE" fi ;; *) echo "$0: Unknown type" >&2 ; exit 1 ;; esac