From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 384503858C33 for ; Sat, 30 Jul 2022 11:37:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 384503858C33 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-410-IWZL9Z9yNOWpVLXyG-J2XA-1; Sat, 30 Jul 2022 07:37:08 -0400 X-MC-Unique: IWZL9Z9yNOWpVLXyG-J2XA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1732F101A54E; Sat, 30 Jul 2022 11:37:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCAD51121314; Sat, 30 Jul 2022 11:37:07 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 26UBb5Np2075143 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 30 Jul 2022 13:37:05 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 26UBb5sr2075142; Sat, 30 Jul 2022 13:37:05 +0200 Date: Sat, 30 Jul 2022 13:37:04 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH] libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jul 2022 11:37:14 -0000 Hi! 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. Bootstrapped/regtested on powerpc64le-linux, ok for trunk / 12.2? 2022-07-30 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}. --- libgfortran/io/transfer.c.jj 2022-01-11 23:49:53.695803219 +0100 +++ libgfortran/io/transfer.c 2022-07-29 16:26:58.414855021 +0200 @@ -1614,6 +1614,10 @@ formatted_transfer_scalar_read (st_param 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_param 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_param 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_para 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_para 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_para 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; Jakub