From 8dbc86adf3e4da2ea284955ede94a0b30acc6d36 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Tue, 14 Jul 2020 12:31:16 -0700 Subject: [PATCH] [flang] Fix list-directed input (repeated nulls and LOGICAL) Allow repeated nulls in list-directed input (e.g., "4*,") and ignore excess characters in list-directed LOGICAL input after the T or F. Fixes FCVS test fm923.f. Reviewed By: sscalpone Differential Revision: https://reviews.llvm.org/D83810 --- flang/runtime/edit-input.cpp | 3 +++ flang/runtime/io-stmt.cpp | 18 +++++++++++++----- flang/unittests/Runtime/list-input.cpp | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/flang/runtime/edit-input.cpp b/flang/runtime/edit-input.cpp index f710c1107ec1..27e8122d9ae6 100644 --- a/flang/runtime/edit-input.cpp +++ b/flang/runtime/edit-input.cpp @@ -337,6 +337,9 @@ bool EditLogicalInput(IoStatementState &io, const DataEdit &edit, bool &x) { } if (remaining) { // ignore the rest of the field io.HandleRelativePosition(*remaining); + } else if (edit.descriptor == DataEdit::ListDirected) { + while (io.NextInField(remaining)) { // discard rest of field + } } return true; } diff --git a/flang/runtime/io-stmt.cpp b/flang/runtime/io-stmt.cpp index a4d8af4f7211..0681da215d1e 100644 --- a/flang/runtime/io-stmt.cpp +++ b/flang/runtime/io-stmt.cpp @@ -472,6 +472,10 @@ ListDirectedStatementState::GetNextDataEdit( edit.descriptor = DataEdit::ListDirectedNullValue; return edit; } + char32_t comma{','}; + if (io.mutableModes().editingFlags & decimalComma) { + comma = ';'; + } if (remaining_ > 0 && !realPart_) { // "r*c" repetition in progress while (connection.currentRecordNumber > initialRecordNumber_) { io.BackspaceRecord(); @@ -479,6 +483,10 @@ ListDirectedStatementState::GetNextDataEdit( connection.HandleAbsolutePosition(initialPositionInRecord_); if (!imaginaryPart_) { edit.repeat = std::min(remaining_, maxRepeat); + auto ch{io.GetNextNonBlank()}; + if (!ch || *ch == ' ' || *ch == comma) { // "r*" repeated null + edit.descriptor = DataEdit::ListDirectedNullValue; + } } remaining_ -= edit.repeat; return edit; @@ -503,10 +511,6 @@ ListDirectedStatementState::GetNextDataEdit( edit.descriptor = DataEdit::ListDirectedNullValue; return edit; } - char32_t comma{','}; - if (io.mutableModes().editingFlags & decimalComma) { - comma = ';'; - } bool isFirstItem{isFirstItem_}; isFirstItem_ = false; if (*ch == comma) { @@ -544,10 +548,14 @@ ListDirectedStatementState::GetNextDataEdit( if (r > 0 && ch && *ch == '*') { // subtle: r must be nonzero io.HandleRelativePosition(1); ch = io.GetCurrentChar(); - if (!ch || *ch == ' ' || *ch == comma || *ch == '/') { // "r*" null + if (ch && *ch == '/') { // r*/ + hitSlash_ = true; edit.descriptor = DataEdit::ListDirectedNullValue; return edit; } + if (!ch || *ch == ' ' || *ch == comma) { // "r*" null + edit.descriptor = DataEdit::ListDirectedNullValue; + } edit.repeat = std::min(r, maxRepeat); remaining_ = r - edit.repeat; initialRecordNumber_ = connection.currentRecordNumber; diff --git a/flang/unittests/Runtime/list-input.cpp b/flang/unittests/Runtime/list-input.cpp index c7a660dc87aa..9ec77080203a 100644 --- a/flang/unittests/Runtime/list-input.cpp +++ b/flang/unittests/Runtime/list-input.cpp @@ -15,7 +15,7 @@ int main() { char buffer[4][32]; int j{0}; - for (const char *p : {"1 2 2*3 ,", ",6,,8,123*", + for (const char *p : {"1 2 2*3 ,", ",6,,8,1*", "2*'abcdefghijklmnopqrstuvwxyzABC", "DEFGHIJKLMNOPQRSTUVWXYZ'"}) { SetCharacter(buffer[j++], sizeof buffer[0], p); }