aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2025-01-17 21:20:31 +0100
committerHarald Anlauf <anlauf@gmx.de>2025-01-17 22:38:41 +0100
commitca2681d45a45077010bcc5a4547450044bdd6d78 (patch)
tree7d29c1fe48872bf45a7bd70841bff36cbd6a9b04
parent9f009e8865cda01310c52f7ec8bdaa3c557a2745 (diff)
downloadgcc-ca2681d45a45077010bcc5a4547450044bdd6d78.zip
gcc-ca2681d45a45077010bcc5a4547450044bdd6d78.tar.gz
gcc-ca2681d45a45077010bcc5a4547450044bdd6d78.tar.bz2
libfortran: G formatting for UNSIGNED [PR118536]
PR libfortran/118536 libgfortran/ChangeLog: * io/transfer.c (formatted_transfer_scalar_write): Handle UNSIGNED in G formatting. gcc/testsuite/ChangeLog: * gfortran.dg/unsigned_write_2.f90: New test.
-rw-r--r--gcc/testsuite/gfortran.dg/unsigned_write_2.f9030
-rw-r--r--libgfortran/io/transfer.c3
2 files changed, 33 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/unsigned_write_2.f90 b/gcc/testsuite/gfortran.dg/unsigned_write_2.f90
new file mode 100644
index 0000000..091e9b9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unsigned_write_2.f90
@@ -0,0 +1,30 @@
+! { dg-do run }
+! This is a libgfortran (runtime library) test, need to run only once!
+!
+! { dg-additional-options "-funsigned" }
+!
+! PR libfortran/118536 - G formatting for UNSIGNED
+
+program print_unsigned_g_formatted
+ character(21) :: s1, s2
+ unsigned(1) :: u1 = huge(0U_1)
+ unsigned(2) :: u2 = huge(0U_2)
+ unsigned(4) :: u4 = huge(0U_4)
+ unsigned(8) :: u8 = huge(0U_8)
+
+ write(s1,'(i0)') u1
+ write(s2,'(g0)') u1
+ if (s1 /= s2) stop 1
+
+ write(s1,'(i0)') u2
+ write(s2,'(g0)') u2
+ if (s1 /= s2) stop 2
+
+ write(s1,'(i0)') u4
+ write(s2,'(g0)') u4
+ if (s1 /= s2) stop 3
+
+ write(s1,'(i0)') u8
+ write(s2,'(g0)') u8
+ if (s1 /= s2) stop 4
+end
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 0177e05..b3b72f3 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -2365,6 +2365,9 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
case BT_INTEGER:
write_i (dtp, f, p, kind);
break;
+ case BT_UNSIGNED:
+ write_iu (dtp, f, p, kind);
+ break;
case BT_LOGICAL:
write_l (dtp, f, p, kind);
break;