From 3fff828efbc616ad730ba40aab4e1e2e13376a20 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 18 Apr 2025 08:19:35 -0700 Subject: [PATCH] [flang] Tweak integer output under width-free I/G editing A recent patch fixed Fujitsu test case 0561_0168 by emitting a leading space for "bare" (no width 'w') I and G output editing of integer values. This fix has broken another Fujitsu test case (0561_0168), since the leading space should not be produced at the first column of the output record. Adjust. --- flang-rt/lib/runtime/edit-output.cpp | 7 +++++-- flang-rt/unittests/Runtime/NumericalFormatTest.cpp | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/flang-rt/lib/runtime/edit-output.cpp b/flang-rt/lib/runtime/edit-output.cpp index 3699213e1f7b7..f90b6fb10963f 100644 --- a/flang-rt/lib/runtime/edit-output.cpp +++ b/flang-rt/lib/runtime/edit-output.cpp @@ -182,8 +182,11 @@ bool RT_API_ATTRS EditIntegerOutput(IoStatementState &io, const DataEdit &edit, leadingSpaces = 1; } else if (!edit.width) { // Bare 'I' and 'G' are interpreted with various default widths in the - // compilers that support them, so there's always some leading space. - leadingSpaces = std::max(1, leadingSpaces); + // compilers that support them, so there's always some leading space + // after column 1. + if (io.GetConnectionState().positionInRecord > 0) { + leadingSpaces = 1; + } } return EmitRepeated(io, ' ', leadingSpaces) && EmitAscii(io, n < 0 ? "-" : "+", signChars) && diff --git a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp index 36170ea1056fd..a752f9d6c723b 100644 --- a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp +++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp @@ -842,6 +842,10 @@ TEST(IOApiTests, FormatIntegerValues) { {"(G0.2)", -1, "-1"}, {"(G0.2)", 999, "999"}, {"(G0.4)", 999, "999"}, + {"(I)", 999, "999"}, + {"(G)", 999, "999"}, + {"('x',I)", 999, "x 999"}, + {"('x',G)", 999, "x 999"}, }; for (auto const &[fmt, value, expect] : intTestCases) {