[libgfortran] PR117820

Message ID 9c8d4808-1626-4e26-a54a-32d98f014d01@gmail.com
State New
Headers
Series [libgfortran] PR117820 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Jerry D Dec. 3, 2024, 4:13 a.m. UTC
  Hi all,

Attached patch adds a test for zero that is needed for write_boz to work 
correctly. Almost obvious.

Regression tested on x86_64.

Ok for trunk?

Jerry

Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Mon Dec 2 19:45:26 2024 -0800

     Fortran: Fix B64.0 formatted write output.

             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.
  

Comments

Paul Richard Thomas Dec. 3, 2024, 6:51 a.m. UTC | #1
Hi Jerry,

That's fine for trunk and, after a decent interval, I would suggest that
you backport to 14-branch.

Please add the name of the contributor to the testcase unless you have been
asked not to.

Thanks

Paul


On Tue, 3 Dec 2024 at 04:13, Jerry D <jvdelisle2@gmail.com> wrote:

> Hi all,
>
> Attached patch adds a test for zero that is needed for write_boz to work
> correctly. Almost obvious.
>
> Regression tested on x86_64.
>
> Ok for trunk?
>
> Jerry
>
> Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
> Date:   Mon Dec 2 19:45:26 2024 -0800
>
>      Fortran: Fix B64.0 formatted write output.
>
>              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.
>
>
  
Harald Anlauf Dec. 3, 2024, 6:08 p.m. UTC | #2
Hi Jerry,

regarding the testcase, these variants are both standard-conforming and
silent under -pedantic:

   x = ibset (0_8, 63)
   x = ibset (0_8, bit_size(x)-1)

No trickery needed.

Cheers,
Harald

Am 03.12.24 um 05:13 schrieb Jerry D:
> Hi all,
>
> Attached patch adds a test for zero that is needed for write_boz to work
> correctly. Almost obvious.
>
> Regression tested on x86_64.
>
> Ok for trunk?
>
> Jerry
>
> Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
> Date:   Mon Dec 2 19:45:26 2024 -0800
>
>      Fortran: Fix B64.0 formatted write output.
>
>              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.
>
  

Patch

diff --git a/gcc/testsuite/gfortran.dg/pr117820.f90 b/gcc/testsuite/gfortran.dg/pr117820.f90
new file mode 100644
index 00000000000..e873393f2ef
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr117820.f90
@@ -0,0 +1,12 @@ 
+! { dg-do run }
+! { dg-options "-std=gnu" }
+! see pr117820, -std=gnu for this test needed to avoid a warning with -pedantic
+! on line 9 below.
+program test
+  integer(8) :: x
+  character(80) :: output
+  output = "garbage"
+  x = -huge(x) - 1_8
+  write(output, '("<",B64.0,">")') x
+  if (output .ne. "<1000000000000000000000000000000000000000000000000000000000000000>") stop 1
+end program
diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c
index 2f414c6b57d..ccb2b5cb810 100644
--- a/libgfortran/io/write.c
+++ b/libgfortran/io/write.c
@@ -1392,6 +1392,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);
     }
 }