Skip to content

Commit 03ef1cb

Browse files
committed
Revert "[flang][runtime] Refine state associated with child I/O (llvm#150461)"
breaks 519, 528, 535 for MPI, OMP, and TGT runtime error This reverts commit 918d6db.
1 parent 85e5964 commit 03ef1cb

File tree

4 files changed

+30
-81
lines changed

4 files changed

+30
-81
lines changed

flang-rt/include/flang-rt/runtime/io-stmt.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ class IoStatementState {
8484
// This design avoids virtual member functions and function pointers,
8585
// which may not have good support in some runtime environments.
8686

87-
RT_API_ATTRS const NonTbpDefinedIoTable *nonTbpDefinedIoTable() const;
88-
RT_API_ATTRS void set_nonTbpDefinedIoTable(const NonTbpDefinedIoTable *);
89-
9087
// CompleteOperation() is the last opportunity to raise an I/O error.
9188
// It is called by EndIoStatement(), but it can be invoked earlier to
9289
// catch errors for (e.g.) GetIoMsg() and GetNewUnit(). If called
@@ -366,13 +363,6 @@ class IoStatementBase : public IoErrorHandler {
366363
using IoErrorHandler::IoErrorHandler;
367364

368365
RT_API_ATTRS bool completedOperation() const { return completedOperation_; }
369-
RT_API_ATTRS const NonTbpDefinedIoTable *nonTbpDefinedIoTable() const {
370-
return nonTbpDefinedIoTable_;
371-
}
372-
RT_API_ATTRS void set_nonTbpDefinedIoTable(
373-
const NonTbpDefinedIoTable *table) {
374-
nonTbpDefinedIoTable_ = table;
375-
}
376366

377367
RT_API_ATTRS void CompleteOperation() { completedOperation_ = true; }
378368
RT_API_ATTRS int EndIoStatement() { return GetIoStat(); }
@@ -407,11 +397,6 @@ class IoStatementBase : public IoErrorHandler {
407397

408398
protected:
409399
bool completedOperation_{false};
410-
411-
private:
412-
// Original NonTbpDefinedIoTable argument to Input/OutputDerivedType,
413-
// saved here so that it can also be used in child I/O statements.
414-
const NonTbpDefinedIoTable *nonTbpDefinedIoTable_{nullptr};
415400
};
416401

417402
// Common state for list-directed & NAMELIST I/O, both internal & external
@@ -645,10 +630,8 @@ class ChildIoStatementState : public IoStatementBase,
645630
public:
646631
RT_API_ATTRS ChildIoStatementState(
647632
ChildIo &, const char *sourceFile = nullptr, int sourceLine = 0);
648-
RT_API_ATTRS const NonTbpDefinedIoTable *nonTbpDefinedIoTable() const;
649-
RT_API_ATTRS void set_nonTbpDefinedIoTable(const NonTbpDefinedIoTable *);
650633
RT_API_ATTRS ChildIo &child() { return child_; }
651-
RT_API_ATTRS MutableModes &mutableModes() { return mutableModes_; }
634+
RT_API_ATTRS MutableModes &mutableModes();
652635
RT_API_ATTRS ConnectionState &GetConnectionState();
653636
RT_API_ATTRS ExternalFileUnit *GetExternalFileUnit() const;
654637
RT_API_ATTRS int EndIoStatement();
@@ -661,7 +644,6 @@ class ChildIoStatementState : public IoStatementBase,
661644

662645
private:
663646
ChildIo &child_;
664-
MutableModes mutableModes_;
665647
};
666648

667649
template <Direction DIR, typename CHAR>
@@ -672,6 +654,7 @@ class ChildFormattedIoStatementState : public ChildIoStatementState<DIR>,
672654
RT_API_ATTRS ChildFormattedIoStatementState(ChildIo &, const CharType *format,
673655
std::size_t formatLength, const Descriptor *formatDescriptor = nullptr,
674656
const char *sourceFile = nullptr, int sourceLine = 0);
657+
RT_API_ATTRS MutableModes &mutableModes() { return mutableModes_; }
675658
RT_API_ATTRS void CompleteOperation();
676659
RT_API_ATTRS int EndIoStatement();
677660
RT_API_ATTRS bool AdvanceRecord(int = 1);
@@ -681,6 +664,7 @@ class ChildFormattedIoStatementState : public ChildIoStatementState<DIR>,
681664
}
682665

683666
private:
667+
MutableModes mutableModes_;
684668
FormatControl<ChildFormattedIoStatementState> format_;
685669
};
686670

@@ -856,7 +840,7 @@ class InquireUnconnectedFileState : public NoUnitIoStatementState {
856840
};
857841

858842
class InquireIOLengthState : public NoUnitIoStatementState,
859-
public IoDirectionState<Direction::Output> {
843+
public OutputStatementState {
860844
public:
861845
RT_API_ATTRS InquireIOLengthState(
862846
const char *sourceFile = nullptr, int sourceLine = 0);

flang-rt/lib/runtime/descriptor-io.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,15 @@ static RT_API_ATTRS Fortran::common::optional<bool> DefinedFormattedIo(
4747
const typeInfo::DerivedType &derived,
4848
const typeInfo::SpecialBinding &special,
4949
const SubscriptValue subscripts[]) {
50-
// Look at the next data edit descriptor. If this is list-directed I/O, the
51-
// "maxRepeat=0" argument will prevent the input from advancing over an
52-
// initial '(' that shouldn't be consumed now as the start of a real part.
53-
Fortran::common::optional<DataEdit> peek{io.GetNextDataEdit(/*maxRepeat=*/0)};
50+
Fortran::common::optional<DataEdit> peek{
51+
io.GetNextDataEdit(0 /*to peek at it*/)};
5452
if (peek &&
5553
(peek->descriptor == DataEdit::DefinedDerivedType ||
56-
peek->descriptor == DataEdit::ListDirected ||
57-
peek->descriptor == DataEdit::ListDirectedRealPart)) {
54+
peek->descriptor == DataEdit::ListDirected)) {
5855
// Defined formatting
5956
IoErrorHandler &handler{io.GetIoErrorHandler()};
60-
DataEdit edit{peek->descriptor == DataEdit::ListDirectedRealPart
61-
? *peek
62-
: *io.GetNextDataEdit(1)};
57+
DataEdit edit{*io.GetNextDataEdit(1)}; // now consume it; no repeats
58+
RUNTIME_CHECK(handler, edit.descriptor == peek->descriptor);
6359
char ioType[2 + edit.maxIoTypeChars];
6460
auto ioTypeLen{std::size_t{2} /*"DT"*/ + edit.ioTypeChars};
6561
if (edit.descriptor == DataEdit::DefinedDerivedType) {
@@ -840,23 +836,13 @@ template RT_API_ATTRS int DescriptorIoTicket<Direction::Input>::Continue(
840836

841837
template <Direction DIR>
842838
RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
843-
const Descriptor &descriptor, const NonTbpDefinedIoTable *originalTable) {
839+
const Descriptor &descriptor, const NonTbpDefinedIoTable *table) {
844840
bool anyIoTookPlace{false};
845-
const NonTbpDefinedIoTable *defaultTable{io.nonTbpDefinedIoTable()};
846-
const NonTbpDefinedIoTable *table{originalTable};
847-
if (!table) {
848-
table = defaultTable;
849-
} else if (table != defaultTable) {
850-
io.set_nonTbpDefinedIoTable(table); // for nested I/O
851-
}
852841
WorkQueue workQueue{io.GetIoErrorHandler()};
853842
if (workQueue.BeginDescriptorIo<DIR>(io, descriptor, table, anyIoTookPlace) ==
854843
StatContinue) {
855844
workQueue.Run();
856845
}
857-
if (defaultTable != table) {
858-
io.set_nonTbpDefinedIoTable(defaultTable);
859-
}
860846
return anyIoTookPlace;
861847
}
862848

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static RT_API_ATTRS bool CheckCompleteListDirectedField(
3737
if (edit.IsListDirected()) {
3838
std::size_t byteCount;
3939
if (auto ch{io.GetCurrentChar(byteCount)}) {
40-
if (!IsCharValueSeparator(edit, *ch)) {
40+
if (IsCharValueSeparator(edit, *ch)) {
41+
return true;
42+
} else {
4143
const auto &connection{io.GetConnectionState()};
4244
io.GetIoErrorHandler().SignalError(IostatBadListDirectedInputSeparator,
4345
"invalid character (0x%x) after list-directed input value, "
@@ -47,9 +49,12 @@ static RT_API_ATTRS bool CheckCompleteListDirectedField(
4749
static_cast<int>(connection.currentRecordNumber));
4850
return false;
4951
}
52+
} else {
53+
return true; // end of record: ok
5054
}
55+
} else {
56+
return true;
5157
}
52-
return true;
5358
}
5459

5560
template <int LOG2_BASE>
@@ -532,11 +537,9 @@ static RT_API_ATTRS ScannedRealInput ScanRealInput(
532537
io.SkipSpaces(remaining);
533538
next = io.NextInField(remaining, edit);
534539
}
535-
if (!next || *next == ')') { // NextInField fails on separators like ')'
540+
if (!next) { // NextInField fails on separators like ')'
536541
std::size_t byteCount{0};
537-
if (!next) {
538-
next = io.GetCurrentChar(byteCount);
539-
}
542+
next = io.GetCurrentChar(byteCount);
540543
if (next && *next == ')') {
541544
io.HandleRelativePosition(byteCount);
542545
}

flang-rt/lib/runtime/io-stmt.cpp

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,6 @@ Fortran::common::optional<DataEdit> IoStatementState::GetNextDataEdit(int n) {
526526
[&](auto &x) { return x.get().GetNextDataEdit(*this, n); }, u_);
527527
}
528528

529-
const NonTbpDefinedIoTable *IoStatementState::nonTbpDefinedIoTable() const {
530-
return common::visit(
531-
[&](auto &x) { return x.get().nonTbpDefinedIoTable(); }, u_);
532-
}
533-
534-
void IoStatementState::set_nonTbpDefinedIoTable(
535-
const NonTbpDefinedIoTable *table) {
536-
common::visit(
537-
[&](auto &x) { return x.get().set_nonTbpDefinedIoTable(table); }, u_);
538-
}
539-
540529
bool IoStatementState::Emit(
541530
const char *data, std::size_t bytes, std::size_t elementBytes) {
542531
return common::visit(
@@ -644,10 +633,10 @@ IoStatementState::FastAsciiField IoStatementState::GetUpcomingFastAsciiField() {
644633
if (!connection.isUTF8 && connection.internalIoCharKind <= 1) {
645634
const char *p{nullptr};
646635
if (std::size_t bytes{GetNextInputBytes(p)}) {
647-
return FastAsciiField{connection, p, bytes};
636+
return FastAsciiField(connection, p, bytes);
648637
}
649638
}
650-
return FastAsciiField{connection};
639+
return FastAsciiField(connection);
651640
}
652641

653642
Fortran::common::optional<char32_t> IoStatementState::NextInField(
@@ -931,12 +920,9 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
931920
fastField.connection().positionInRecord = start;
932921
}
933922
}
934-
if (!imaginaryPart_ && edit.descriptor == DataEdit::ListDirected && ch &&
935-
*ch == '(') {
936-
if (maxRepeat > 0) { // not being peeked at fram DefinedFormattedIo()
937-
realPart_ = true;
938-
fastField.connection().HandleRelativePosition(byteCount);
939-
}
923+
if (!imaginaryPart_ && ch && *ch == '(') {
924+
realPart_ = true;
925+
fastField.connection().HandleRelativePosition(byteCount);
940926
edit.descriptor = DataEdit::ListDirectedRealPart;
941927
}
942928
return edit;
@@ -966,24 +952,12 @@ bool ExternalUnformattedIoStatementState<DIR>::Receive(
966952
template <Direction DIR>
967953
ChildIoStatementState<DIR>::ChildIoStatementState(
968954
ChildIo &child, const char *sourceFile, int sourceLine)
969-
: IoStatementBase{sourceFile, sourceLine}, child_{child},
970-
mutableModes_{child.parent().mutableModes()} {}
971-
972-
template <Direction DIR>
973-
const NonTbpDefinedIoTable *
974-
ChildIoStatementState<DIR>::nonTbpDefinedIoTable() const {
975-
#if !defined(RT_DEVICE_AVOID_RECURSION)
976-
return child_.parent().nonTbpDefinedIoTable();
977-
#else
978-
ReportUnsupportedChildIo();
979-
#endif
980-
}
955+
: IoStatementBase{sourceFile, sourceLine}, child_{child} {}
981956

982957
template <Direction DIR>
983-
void ChildIoStatementState<DIR>::set_nonTbpDefinedIoTable(
984-
const NonTbpDefinedIoTable *table) {
958+
MutableModes &ChildIoStatementState<DIR>::mutableModes() {
985959
#if !defined(RT_DEVICE_AVOID_RECURSION)
986-
child_.parent().set_nonTbpDefinedIoTable(table);
960+
return child_.parent().mutableModes();
987961
#else
988962
ReportUnsupportedChildIo();
989963
#endif
@@ -1056,7 +1030,9 @@ ChildFormattedIoStatementState<DIR, CHAR>::ChildFormattedIoStatementState(
10561030
ChildIo &child, const CHAR *format, std::size_t formatLength,
10571031
const Descriptor *formatDescriptor, const char *sourceFile, int sourceLine)
10581032
: ChildIoStatementState<DIR>{child, sourceFile, sourceLine},
1059-
format_{*this, format, formatLength, formatDescriptor} {}
1033+
mutableModes_{child.parent().mutableModes()}, format_{*this, format,
1034+
formatLength,
1035+
formatDescriptor} {}
10601036

10611037
template <Direction DIR, typename CHAR>
10621038
void ChildFormattedIoStatementState<DIR, CHAR>::CompleteOperation() {

0 commit comments

Comments
 (0)