Skip to content

Commit 047884e

Browse files
committedJan 18, 2022
[flang] runtime: catch OPEN(ACCESS='DIRECT',POSITION=)
A POSITION= specifier may not be used on a direct access file. Differential Revision: https://reviews.llvm.org/D117596
1 parent e847b30 commit 047884e

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed
 

‎flang/runtime/io-api.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ bool IONAME(SetPos)(Cookie cookie, std::int64_t pos) {
519519
ConnectionState &connection{io.GetConnectionState()};
520520
if (connection.access != Access::Stream) {
521521
io.GetIoErrorHandler().SignalError(
522-
"REC= may not appear unless ACCESS='STREAM'");
522+
"POS= may not appear unless ACCESS='STREAM'");
523523
return false;
524524
}
525525
if (pos < 1) {

‎flang/runtime/io-stmt.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,30 @@ void OpenStatementState::set_path(const char *path, std::size_t length) {
208208
}
209209

210210
int OpenStatementState::EndIoStatement() {
211+
if (position_) {
212+
if (access_ && *access_ == Access::Direct) {
213+
SignalError("POSITION= may not be set with ACCESS='DIRECT'");
214+
position_.reset();
215+
}
216+
}
211217
if (path_.get() || wasExtant_ ||
212218
(status_ && *status_ == OpenStatus::Scratch)) {
213-
unit().OpenUnit(status_, action_, position_, std::move(path_), pathLength_,
214-
convert_, *this);
219+
unit().OpenUnit(status_, action_, position_.value_or(Position::AsIs),
220+
std::move(path_), pathLength_, convert_, *this);
215221
} else {
216-
unit().OpenAnonymousUnit(status_, action_, position_, convert_, *this);
222+
unit().OpenAnonymousUnit(
223+
status_, action_, position_.value_or(Position::AsIs), convert_, *this);
217224
}
218225
if (access_) {
219226
if (*access_ != unit().access) {
220227
if (wasExtant_) {
221228
SignalError("ACCESS= may not be changed on an open unit");
229+
access_.reset();
222230
}
223231
}
224-
unit().access = *access_;
232+
if (access_) {
233+
unit().access = *access_;
234+
}
225235
}
226236
if (!unit().isUnformatted) {
227237
unit().isUnformatted = isUnformatted_;

‎flang/runtime/io-stmt.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class OpenStatementState : public ExternalIoStatementBase {
577577
private:
578578
bool wasExtant_;
579579
std::optional<OpenStatus> status_;
580-
Position position_{Position::AsIs};
580+
std::optional<Position> position_;
581581
std::optional<Action> action_;
582582
Convert convert_{Convert::Native};
583583
OwningPtr<char> path_;

0 commit comments

Comments
 (0)