[flang-commits] [flang] 9b64811 - [flang][runtime] Skip unused truncated list-directed character input (#118320)
via flang-commits
flang-commits at lists.llvm.org
Mon Dec 2 12:26:30 PST 2024
Author: Peter Klausler
Date: 2024-12-02T12:26:27-08:00
New Revision: 9b64811e27f8377b77f8561cf678c9d2f2d67393
URL: https://github.com/llvm/llvm-project/commit/9b64811e27f8377b77f8561cf678c9d2f2d67393
DIFF: https://github.com/llvm/llvm-project/commit/9b64811e27f8377b77f8561cf678c9d2f2d67393.diff
LOG: [flang][runtime] Skip unused truncated list-directed character input (#118320)
When reading non-delimited list-directed character input, read the whole
field even if it doesn't fit into the variable.
Fixes https://github.com/llvm/llvm-project/issues/118277.
Added:
Modified:
flang/runtime/edit-input.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp
index 2cee35e23f31a3..b5725a90ba82ac 100644
--- a/flang/runtime/edit-input.cpp
+++ b/flang/runtime/edit-input.cpp
@@ -976,14 +976,10 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
return false;
}
// Undelimited list-directed character input: stop at a value separator
- // or the end of the current record. Subtlety: the "remaining" count
- // here is a dummy that's used to avoid the interpretation of separators
- // in NextInField.
- Fortran::common::optional<int> remaining{length > 0 ? maxUTF8Bytes : 0};
- while (Fortran::common::optional<char32_t> next{
- io.NextInField(remaining, edit)}) {
+ // or the end of the current record.
+ while (auto ch{io.GetCurrentChar(byteCount)}) {
bool isSep{false};
- switch (*next) {
+ switch (*ch) {
case ' ':
case '\t':
case '/':
@@ -1003,11 +999,17 @@ static RT_API_ATTRS bool EditListDirectedCharacterInput(
break;
}
if (isSep) {
- remaining = 0;
- } else {
- *x++ = *next;
- remaining = --length > 0 ? maxUTF8Bytes : 0;
+ break;
+ }
+ if (length > 0) {
+ *x++ = *ch;
+ --length;
+ } else if (edit.IsNamelist()) {
+ // GNU compatibility
+ break;
}
+ io.HandleRelativePosition(byteCount);
+ io.GotChar(byteCount);
}
Fortran::runtime::fill_n(x, length, ' ');
return true;
More information about the flang-commits
mailing list