[flang-commits] [flang] e9d0f8b - [flang] Don't drop format string for external child I/O

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sat Jan 22 09:01:11 PST 2022


Author: Peter Klausler
Date: 2022-01-22T09:01:02-08:00
New Revision: e9d0f8baf2361b190b0ffde67cad62828fda8ce6

URL: https://github.com/llvm/llvm-project/commit/e9d0f8baf2361b190b0ffde67cad62828fda8ce6
DIFF: https://github.com/llvm/llvm-project/commit/e9d0f8baf2361b190b0ffde67cad62828fda8ce6.diff

LOG: [flang] Don't drop format string for external child I/O

In user-defined derived type I/O to an external unit, don't
omit the format string from the constructor of ChildFormattedIoStatement.
And include any user IOMSG text in the crash message of the
parent, if it doesn't catch errors.

Differential Revision: https://reviews.llvm.org/D117903

Added: 
    

Modified: 
    flang/runtime/format-implementation.h
    flang/runtime/io-api.cpp
    flang/runtime/io-error.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/format-implementation.h b/flang/runtime/format-implementation.h
index b9c1b8427afe3..6b1a64b96a851 100644
--- a/flang/runtime/format-implementation.h
+++ b/flang/runtime/format-implementation.h
@@ -353,7 +353,7 @@ DataEdit FormatControl<CONTEXT>::GetNextDataEdit(
       ++offset_;
     }
   } else if (edit.descriptor == 'D' && Capitalize(PeekNext()) == 'T') {
-    // DT'iotype'(v_list) user-defined derived type I/O
+    // DT['iotype'][(v_list)] user-defined derived type I/O
     edit.descriptor = DataEdit::DefinedDerivedType;
     ++offset_;
     if (auto quote{static_cast<char>(PeekNext())};

diff  --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 64c798d7ff8ae..9c50adf184898 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -215,7 +215,7 @@ Cookie BeginExternalFormattedIO(const char *format, std::size_t formatLength,
                                         : "formatted input",
                false, DIR)
         ? &child->BeginIoStatement<ChildFormattedIoStatementState<DIR>>(
-              *child, sourceFile, sourceLine)
+              *child, format, formatLength, sourceFile, sourceLine)
         : nullptr;
   } else {
     IoErrorHandler handler{terminator};

diff  --git a/flang/runtime/io-error.cpp b/flang/runtime/io-error.cpp
index 48647ec8805e7..e139e0649e503 100644
--- a/flang/runtime/io-error.cpp
+++ b/flang/runtime/io-error.cpp
@@ -59,10 +59,14 @@ void IoErrorHandler::SignalError(int iostatOrErrno) {
 
 void IoErrorHandler::Forward(
     int ioStatOrErrno, const char *msg, std::size_t length) {
-  SignalError(ioStatOrErrno);
-  if (ioStat_ != IostatOk && (flags_ & hasIoMsg)) {
+  if (ioStat_ != IostatOk && msg && (flags_ & hasIoMsg)) {
     ioMsg_ = SaveDefaultCharacter(msg, length, *this);
   }
+  if (ioStatOrErrno != IostatOk && msg) {
+    SignalError(ioStatOrErrno, "%.*s", static_cast<int>(length), msg);
+  } else {
+    SignalError(ioStatOrErrno);
+  }
 }
 
 void IoErrorHandler::SignalErrno() { SignalError(errno); }


        


More information about the flang-commits mailing list