[flang-commits] [flang] 3f6dbf1 - [flang] Don't close stderr in runtime (fixes STOP output)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Dec 1 13:25:26 PST 2021
Author: Peter Klausler
Date: 2021-12-01T13:25:18-08:00
New Revision: 3f6dbf1a75b259e242116820aec040b4b72d9296
URL: https://github.com/llvm/llvm-project/commit/3f6dbf1a75b259e242116820aec040b4b72d9296
DIFF: https://github.com/llvm/llvm-project/commit/3f6dbf1a75b259e242116820aec040b4b72d9296.diff
LOG: [flang] Don't close stderr in runtime (fixes STOP output)
STOP statement output was sometimes failing to appear because
the runtime flushes and shuts down open Fortran units beforehand.
But when file descriptor 2 was closed, the STOP statement output
was suppressed. The fix is to not actually close file descriptors
0-2 if they are connected to Fortran units being closed. This was
already the policy when an OPEN statement was (re-)opening such a
unit, so that logic has been pulled out into a member function and
shared with CLOSE processing.
Differential Revision: https://reviews.llvm.org/D114897
Added:
Modified:
flang/runtime/file.cpp
flang/runtime/file.h
Removed:
################################################################################
diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index aaa2e30f4d17c..00263fb31e78d 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -66,16 +66,7 @@ void OpenFile::Open(OpenStatus status, std::optional<Action> action,
(status == OpenStatus::Old || status == OpenStatus::Unknown)) {
return;
}
- if (fd_ >= 0) {
- if (fd_ <= 2) {
- // don't actually close a standard file descriptor, we might need it
- } else {
- if (::close(fd_) != 0) {
- handler.SignalErrno();
- }
- }
- fd_ = -1;
- }
+ CloseFd(handler);
if (status == OpenStatus::Scratch) {
if (path_.get()) {
handler.SignalError("FILE= must not appear with STATUS='SCRATCH'");
@@ -179,12 +170,7 @@ void OpenFile::Close(CloseStatus status, IoErrorHandler &handler) {
break;
}
path_.reset();
- if (fd_ >= 0) {
- if (::close(fd_) != 0) {
- handler.SignalErrno();
- }
- fd_ = -1;
- }
+ CloseFd(handler);
}
std::size_t OpenFile::Read(FileOffset at, char *buffer, std::size_t minBytes,
@@ -410,6 +396,19 @@ int OpenFile::PendingResult(const Terminator &terminator, int iostat) {
return id;
}
+void OpenFile::CloseFd(IoErrorHandler &handler) {
+ if (fd_ >= 0) {
+ if (fd_ <= 2) {
+ // don't actually close a standard file descriptor, we might need it
+ } else {
+ if (::close(fd_) != 0) {
+ handler.SignalErrno();
+ }
+ }
+ fd_ = -1;
+ }
+}
+
bool IsATerminal(int fd) { return ::isatty(fd); }
#ifdef WIN32
diff --git a/flang/runtime/file.h b/flang/runtime/file.h
index cde3c194de94e..137d643f74ae2 100644
--- a/flang/runtime/file.h
+++ b/flang/runtime/file.h
@@ -85,6 +85,7 @@ class OpenFile {
position_ = pos;
openPosition_.reset();
}
+ void CloseFd(IoErrorHandler &);
int fd_{-1};
OwningPtr<char> path_;
More information about the flang-commits
mailing list