[flang] Extension: allow char string edit descriptors in input formats (#140624)

FORMAT("J=",I3) is accepted by a few other Fortran compilers as a valid
format for input as well as for output. The character string edit
descriptor "J=" is interpreted as if it had been 2X on input, causing
two characters to be skipped over. The skipped characters don't have to
match the characters in the literal string. An optional warning is
emitted under control of the -pedantic option.
This commit is contained in:
Peter Klausler
2025-05-28 13:58:22 -07:00
committed by GitHub
parent b574c811e8
commit 4c6b60a639
5 changed files with 23 additions and 9 deletions

View File

@@ -427,7 +427,11 @@ RT_API_ATTRS int FormatControl<CONTEXT>::CueUpNextDataEdit(
} else {
--chars;
}
EmitAscii(context, format_ + start, chars);
if constexpr (std::is_base_of_v<InputStatementState, CONTEXT>) {
context.HandleRelativePosition(chars);
} else {
EmitAscii(context, format_ + start, chars);
}
} else if (ch == 'H') {
// 9HHOLLERITH
if (!repeat || *repeat < 1 || offset_ + *repeat > formatLength_) {
@@ -435,7 +439,12 @@ RT_API_ATTRS int FormatControl<CONTEXT>::CueUpNextDataEdit(
maybeReversionPoint);
return 0;
}
EmitAscii(context, format_ + offset_, static_cast<std::size_t>(*repeat));
if constexpr (std::is_base_of_v<InputStatementState, CONTEXT>) {
context.HandleRelativePosition(static_cast<std::size_t>(*repeat));
} else {
EmitAscii(
context, format_ + offset_, static_cast<std::size_t>(*repeat));
}
offset_ += *repeat;
} else if (ch >= 'A' && ch <= 'Z') {
int start{offset_ - 1};

View File

@@ -882,6 +882,7 @@ TEST(IOApiTests, EditDoubleInputValues) {
{"(F18.1)", " 125", 0x4029000000000000, 0},
{"(F18.2)", " 125", 0x3ff4000000000000, 0},
{"(F18.3)", " 125", 0x3fc0000000000000, 0},
{"('str',F3.0)", "xxx125", 0x405f400000000000, 0},
{"(-1P,F18.0)", " 125", 0x4093880000000000, 0}, // 1250
{"(1P,F18.0)", " 125", 0x4029000000000000, 0}, // 12.5
{"(BZ,F18.0)", " 125 ", 0x4093880000000000, 0}, // 1250