Skip to content

Commit 03b3620

Browse files
authored
[flang] Tweak integer output under width-free I/G editing (#136316)
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.
1 parent 0dd2ed4 commit 03b3620

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

flang-rt/lib/runtime/edit-output.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ bool RT_API_ATTRS EditIntegerOutput(IoStatementState &io, const DataEdit &edit,
182182
leadingSpaces = 1;
183183
} else if (!edit.width) {
184184
// Bare 'I' and 'G' are interpreted with various default widths in the
185-
// compilers that support them, so there's always some leading space.
186-
leadingSpaces = std::max(1, leadingSpaces);
185+
// compilers that support them, so there's always some leading space
186+
// after column 1.
187+
if (io.GetConnectionState().positionInRecord > 0) {
188+
leadingSpaces = 1;
189+
}
187190
}
188191
return EmitRepeated(io, ' ', leadingSpaces) &&
189192
EmitAscii(io, n < 0 ? "-" : "+", signChars) &&

flang-rt/unittests/Runtime/NumericalFormatTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ TEST(IOApiTests, FormatIntegerValues) {
842842
{"(G0.2)", -1, "-1"},
843843
{"(G0.2)", 999, "999"},
844844
{"(G0.4)", 999, "999"},
845+
{"(I)", 999, "999"},
846+
{"(G)", 999, "999"},
847+
{"('x',I)", 999, "x 999"},
848+
{"('x',G)", 999, "x 999"},
845849
};
846850

847851
for (auto const &[fmt, value, expect] : intTestCases) {

0 commit comments

Comments
 (0)