[gcc r17-1733] fortran: Fix FMT_X and adjust the test case.

Jerry DeLisle jvdelisle@gcc.gnu.org
Mon Jun 22 05:02:38 GMT 2026


https://gcc.gnu.org/g:471c3c3da9c55fd99f813d16ffa9bde499539333

commit r17-1733-g471c3c3da9c55fd99f813d16ffa9bde499539333
Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
Date:   Sun Jun 21 21:20:41 2026 -0700

    fortran: Fix FMT_X and adjust the test case.
    
            PR libfortran/118774
    
    libgfortran/ChangeLog:
    
            * io/transfer.c (formatted_transfer_scalar_write): Set nspaces
            to number of skips for FMT_X.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/fmt_t_10.f90: Adjust the test case results
            check.

Diff:
---
 gcc/testsuite/gfortran.dg/fmt_t_10.f90 | 2 +-
 libgfortran/io/transfer.c              | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/fmt_t_10.f90 b/gcc/testsuite/gfortran.dg/fmt_t_10.f90
index 1f714d24d4e8..628363dab4f8 100644
--- a/gcc/testsuite/gfortran.dg/fmt_t_10.f90
+++ b/gcc/testsuite/gfortran.dg/fmt_t_10.f90
@@ -10,6 +10,6 @@ program fmt_t_10
    character(21) :: output1, output2
    write (output1, fmt1) 'RADIX', radix(pi)
    write (output2, fmt2) 'RADIX', radix(pi)
-   if (output1 /= 'RADIX.............. 2') stop 1
+   if (output1 /= 'RADIX ............. 2') stop 1
    if (output2 /= 'RADIX ............. 2') stop 2
 end program fmt_t_10
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index de7b6d7df35c..95ead6936f20 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -2423,10 +2423,11 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
 	  if (dtp->u.p.pending_spaces < 0 && dtp->u.p.skips > 0)
 	    {
 	      /* The advance falls within already-written content (e.g. after
-		 a backward tab).  Advance the position without overwriting
-		 the existing characters.  */
+		 a backward tab).  FMT_X sets positions to blank per the
+		 standard; FMT_TR skips without overwriting existing characters.  */
 	      gfc_offset new_max;
-	      write_x (dtp, dtp->u.p.skips, 0);
+	      int nspaces = f->format == FMT_X ? dtp->u.p.skips : 0;
+	      write_x (dtp, dtp->u.p.skips, nspaces);
 
 	      /* Adjust the max position depending on the type of write.  */
 	      if (is_stream_io (dtp))


More information about the Gcc-cvs mailing list