Skip to content

Commit 10f15e2

Browse files
authored
[flang][runtime] Crash more informatively in defined I/O error case (#74134)
Defined unformatted I/O is not allowed except from/to an external unit. This restriction prohibits an INQUIRE(IOLENGTH=n) statement from using derived types with defined unformatted output in its I/O list. The runtime currently detects this case and crashes with an internal error; this patch defines a new I/O error enum and causes the program to crash with a more useful message.
1 parent f2afd10 commit 10f15e2

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

flang/include/flang/Runtime/iostat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ enum Iostat {
8585
IostatBadOpOnChildUnit,
8686
IostatBadNewUnit,
8787
IostatBadListDirectedInputSeparator,
88+
IostatNonExternalDefinedUnformattedIo,
8889
};
8990

9091
const char *IostatErrorString(int);

flang/runtime/descriptor-io.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ bool DefinedUnformattedIo(IoStatementState &io, const Descriptor &descriptor,
119119
// Unformatted I/O must have an external unit (or child thereof).
120120
IoErrorHandler &handler{io.GetIoErrorHandler()};
121121
ExternalFileUnit *external{io.GetExternalFileUnit()};
122-
RUNTIME_CHECK(handler, external != nullptr);
122+
if (!external) { // INQUIRE(IOLENGTH=)
123+
handler.SignalError(IostatNonExternalDefinedUnformattedIo);
124+
return false;
125+
}
123126
ChildIo &child{external->PushChildIo(io)};
124127
int unit{external->unitNumber()};
125128
int ioStat{IostatOk};

flang/runtime/iostat.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ const char *IostatErrorString(int iostat) {
115115
return "NEWUNIT= without FILE= or STATUS='SCRATCH'";
116116
case IostatBadListDirectedInputSeparator:
117117
return "List-directed input value has trailing unused characters";
118+
case IostatNonExternalDefinedUnformattedIo:
119+
return "Defined unformatted I/O without an external unit";
118120
default:
119121
return nullptr;
120122
}

0 commit comments

Comments
 (0)