From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 6FC8C3858CDB; Wed, 3 Aug 2022 09:22:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FC8C3858CDB MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8653] libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: eb941a6d651b9b87f7da7cc5f39b36e7b7082340 X-Git-Newrev: 4e5ca7ff8c9afd3c38245aa6b939cd3ae49bf1fe Message-Id: <20220803092225.6FC8C3858CDB@sourceware.org> Date: Wed, 3 Aug 2022 09:22:25 +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, 03 Aug 2022 09:22:25 -0000 https://gcc.gnu.org/g:4e5ca7ff8c9afd3c38245aa6b939cd3ae49bf1fe commit r12-8653-g4e5ca7ff8c9afd3c38245aa6b939cd3ae49bf1fe Author: Jakub Jelinek Date: Mon Aug 1 08:26:03 2022 +0200 libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079] The boz_15.f90 test FAILs on powerpc64le-linux when -mabi=ieeelongdouble is used (either default through --with-long-double-format=ieee or when used explicitly). The problem is that the read/write transfer routines are called with BT_REAL (or BT_COMPLEX) type and kind 17 which is magic we use to say it is the IEEE quad real(kind=16) rather than the IBM double double real(kind=16). For the floating point input/output we then handle kind 17 specially, but for B/O/Z we just treat the bytes of the floating point value as binary blob and using 17 in that case results in unexpected behavior, for write it means we don't estimate right how many chars we'll need and print ******************** etc. rather than what we should, and even with explicit size we'd print one further byte than intended. For read it would even mean overwriting some unrelated byte after the floating point object. Fixed by using 16 instead of 17 in the read_radix and write_{b,o,z} calls. 2022-08-01 Jakub Jelinek PR libfortran/106079 * io/transfer.c (formatted_transfer_scalar_read, formatted_transfer_scalar_write): For type BT_REAL with kind 17 change kind to 16 before calling read_radix or write_{b,o,z}. (cherry picked from commit 82ac4cd213867be939aedee15347e8fd3f200b6a) Diff: --- libgfortran/io/transfer.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index f543dfd79dc..2760929a1e9 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -1614,6 +1614,10 @@ formatted_transfer_scalar_read (st_parameter_dt *dtp, bt type, void *p, int kind if (!(compile_options.allow_std & GFC_STD_F2008) && require_type (dtp, BT_INTEGER, type, f)) return; +#ifdef HAVE_GFC_REAL_17 + if (type == BT_REAL && kind == 17) + kind = 16; +#endif read_radix (dtp, f, p, kind, 2); break; @@ -1626,6 +1630,10 @@ formatted_transfer_scalar_read (st_parameter_dt *dtp, bt type, void *p, int kind if (!(compile_options.allow_std & GFC_STD_F2008) && require_type (dtp, BT_INTEGER, type, f)) return; +#ifdef HAVE_GFC_REAL_17 + if (type == BT_REAL && kind == 17) + kind = 16; +#endif read_radix (dtp, f, p, kind, 8); break; @@ -1638,6 +1646,10 @@ formatted_transfer_scalar_read (st_parameter_dt *dtp, bt type, void *p, int kind if (!(compile_options.allow_std & GFC_STD_F2008) && require_type (dtp, BT_INTEGER, type, f)) return; +#ifdef HAVE_GFC_REAL_17 + if (type == BT_REAL && kind == 17) + kind = 16; +#endif read_radix (dtp, f, p, kind, 16); break; @@ -2085,6 +2097,10 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin if (!(compile_options.allow_std & GFC_STD_F2008) && require_type (dtp, BT_INTEGER, type, f)) return; +#ifdef HAVE_GFC_REAL_17 + if (type == BT_REAL && kind == 17) + kind = 16; +#endif write_b (dtp, f, p, kind); break; @@ -2097,6 +2113,10 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin if (!(compile_options.allow_std & GFC_STD_F2008) && require_type (dtp, BT_INTEGER, type, f)) return; +#ifdef HAVE_GFC_REAL_17 + if (type == BT_REAL && kind == 17) + kind = 16; +#endif write_o (dtp, f, p, kind); break; @@ -2109,6 +2129,10 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin if (!(compile_options.allow_std & GFC_STD_F2008) && require_type (dtp, BT_INTEGER, type, f)) return; +#ifdef HAVE_GFC_REAL_17 + if (type == BT_REAL && kind == 17) + kind = 16; +#endif write_z (dtp, f, p, kind); break;