public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079]
@ 2022-07-30 11:37 Jakub Jelinek
  2022-07-31 11:01 ` Thomas Koenig
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-07-30 11:37 UTC (permalink / raw)
  To: gcc-patches, fortran

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  <jakub@redhat.com>

	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


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

* Re: [PATCH] libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079]
  2022-07-30 11:37 [PATCH] libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079] Jakub Jelinek
@ 2022-07-31 11:01 ` Thomas Koenig
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2022-07-31 11:01 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches, fortran

Hi Jakub,

> 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?

OK for both.

Best regards

	Thomas

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

end of thread, other threads:[~2022-07-31 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-30 11:37 [PATCH] libfortran: Fix up boz_15.f90 on powerpc64le with -mabi=ieeelongdouble [PR106079] Jakub Jelinek
2022-07-31 11:01 ` Thomas Koenig

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