]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix B64.0 formatted write output.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Wed, 4 Dec 2024 04:55:41 +0000 (20:55 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 6 Dec 2024 18:12:10 +0000 (10:12 -0800)
PR fortran/117820

libgfortran/ChangeLog:

* io/write.c (write_b): Add test for zero needed by write_boz.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr117820.f90: New test.

(cherry picked from commit 7a92ba766815c9a6b73593967a26fdfbebfc7e69)

gcc/testsuite/gfortran.dg/pr117820.f90 [new file with mode: 0644]
libgfortran/io/write.c

diff --git a/gcc/testsuite/gfortran.dg/pr117820.f90 b/gcc/testsuite/gfortran.dg/pr117820.f90
new file mode 100644 (file)
index 0000000..59a4b36
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do run }
+! See pr117820, original testcase provided by Malcolm Cohen.
+program test
+  integer(8) :: x
+  character(80) :: output
+  output = "garbage"
+  x = ibset (0_8, 63)
+  write(output, '("<",B64.0,">")') x
+  if (output .ne. "<1000000000000000000000000000000000000000000000000000000000000000>") stop 1
+end program
index 91d1da2007ae57991b161c42dbee6f16f959f5bf..9d0a0d6102b3c48dfcbac0eac599e3c41f8b7010 100644 (file)
@@ -1260,6 +1260,10 @@ write_b (st_parameter_dt *dtp, const fnode *f, const char *source, int len)
     {
       n = extract_uint (source, len);
       p = btoa (n, itoa_buf, sizeof (itoa_buf));
+
+      /* Test for zero. Needed by write_boz.  */
+      if (n != 0)
+       n = 1;
       write_boz (dtp, f, p, n, len);
     }
 }