Skip to content

Conversation

@klausler
Copy link
Contributor

Always assume that predefined unit 0 is a terminal, so that output to it is never buffered.

Always assume that predefined unit 0 is a terminal, so that output
to it is never buffered.
@klausler klausler requested a review from jeanPerier January 11, 2025 20:12
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Jan 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 11, 2025

@llvm/pr-subscribers-flang-runtime

Author: Peter Klausler (klausler)

Changes

Always assume that predefined unit 0 is a terminal, so that output to it is never buffered.


Full diff: https://github.com/llvm/llvm-project/pull/122614.diff

1 Files Affected:

  • (modified) flang/runtime/file.cpp (+2-2)
diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp
index ec772903242b80..9e077b8cea44bb 100644
--- a/flang/runtime/file.cpp
+++ b/flang/runtime/file.cpp
@@ -134,7 +134,7 @@ void OpenFile::Open(OpenStatus status, Fortran::common::optional<Action> action,
   if (fd_ >= 0 && position == Position::Append && !RawSeekToEnd()) {
     handler.SignalError(IostatOpenBadAppend);
   }
-  isTerminal_ = fd_ >= 0 && IsATerminal(fd_) == 1;
+  isTerminal_ = fd_ >= 0 && IsATerminal(fd_);
   mayRead_ = *action != Action::Write;
   mayWrite_ = *action != Action::Read;
   if (status == OpenStatus::Old || status == OpenStatus::Unknown) {
@@ -163,7 +163,7 @@ void OpenFile::Predefine(int fd) {
   knownSize_.reset();
   nextId_ = 0;
   pending_.reset();
-  isTerminal_ = IsATerminal(fd_) == 1;
+  isTerminal_ = fd == 2 || IsATerminal(fd_);
   mayRead_ = fd == 0;
   mayWrite_ = fd != 0;
   mayPosition_ = false;

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, isatty for FORTRAN_ERROR_UNIT is false when running executables with mpirun, makes sense. LGTM.

@klausler klausler merged commit 874a3ba into llvm:main Jan 14, 2025
11 checks passed
@klausler klausler deleted the bug143 branch January 14, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:runtime flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants