[llvm] [Flang] [Runtime ]Fix write endfile abort (PR #191633)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 04:29:09 PDT 2026


https://github.com/blazie2004 updated https://github.com/llvm/llvm-project/pull/191633

>From f4ae666b2999bdcb0e428c03d5eda06339210fee Mon Sep 17 00:00:00 2001
From: Jay Satish Kumar Patel <kumarpat at pe31.hpc.amslabs.hpecorp.net>
Date: Thu, 23 Apr 2026 01:19:41 -0500
Subject: [PATCH] Fix WRITE after ENDFILE handling using pending IOSTAT

---
 flang-rt/include/flang-rt/runtime/io-error.h | 4 ++++
 flang-rt/lib/runtime/unit.cpp                | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/flang-rt/include/flang-rt/runtime/io-error.h b/flang-rt/include/flang-rt/runtime/io-error.h
index d2180a83f8c3c..088fc76a7909a 100644
--- a/flang-rt/include/flang-rt/runtime/io-error.h
+++ b/flang-rt/include/flang-rt/runtime/io-error.h
@@ -34,6 +34,10 @@ class IoErrorHandler : public Terminator {
   RT_API_ATTRS void HasEorLabel() { flags_ |= hasEor; }
   RT_API_ATTRS void HasIoMsg() { flags_ |= hasIoMsg; }
   RT_API_ATTRS void HasRec() { flags_ |= hasRec; }
+  RT_API_ATTRS void SignalPendingIoStat(int iostat) {
+    if (ioStat_ == IostatOk || ioStat_ == IostatEnd || ioStat_ == IostatEor)
+      ioStat_ = iostat;
+  }
 
   RT_API_ATTRS bool InError() const {
     return ioStat_ != IostatOk || pendingError_ != IostatOk;
diff --git a/flang-rt/lib/runtime/unit.cpp b/flang-rt/lib/runtime/unit.cpp
index c577ae7673127..5dfc1702234a3 100644
--- a/flang-rt/lib/runtime/unit.cpp
+++ b/flang-rt/lib/runtime/unit.cpp
@@ -84,7 +84,7 @@ bool ExternalFileUnit::Emit(const char *data, std::size_t bytes,
     beganReadingRecord_ = false;
   }
   if (IsAfterEndfile()) {
-    handler.SignalError(IostatWriteAfterEndfile);
+    handler.SignalPendingIoStat(IostatWriteAfterEndfile);
     return false;
   }
   CheckDirectAccess(handler);



More information about the llvm-commits mailing list