From 1fe7a187ae9994dc722e8ccfc9132d88201e8519 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 12 Apr 2022 15:15:46 -0700 Subject: [PATCH] [flang][runtime] Don't emit empty lines for bad writes When an error occurs in a formatted sequential output statement and no output was ever emitted, don't emit a blank record. This matches the error case behavior of other Fortran compilers. Differential Revision: https://reviews.llvm.org/D123734 --- flang/runtime/unit.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flang/runtime/unit.cpp b/flang/runtime/unit.cpp index 806e6b16d06b..e7d0fd5f5959 100644 --- a/flang/runtime/unit.cpp +++ b/flang/runtime/unit.cpp @@ -527,6 +527,11 @@ bool ExternalFileUnit::AdvanceRecord(IoErrorHandler &handler) { } else { // Unformatted stream: nothing to do } + } else if (handler.GetIoStat() != IostatOk && + furthestPositionInRecord == 0) { + // Error in formatted variable length record, and no output yet; do + // nothing, like most other Fortran compilers do. + return true; } else { // Terminate formatted variable length record const char *lineEnding{"\n"};