diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp --- a/flang/runtime/edit-output.cpp +++ b/flang/runtime/edit-output.cpp @@ -14,12 +14,21 @@ namespace Fortran::runtime::io { +// In output statement, add a space between numbers and characters. +static void addSpaceBeforeCharacter(IoStatementState &io) { + auto *list{io.get_if>()}; + if (list) { + list->set_lastWasUndelimitedCharacter(false); + } +} + // B/O/Z output of arbitrarily sized data emits a binary/octal/hexadecimal // representation of what is interpreted to be a single unsigned integer value. // When used with character data, endianness is exposed. template static bool EditBOZOutput(IoStatementState &io, const DataEdit &edit, const unsigned char *data0, std::size_t bytes) { + addSpaceBeforeCharacter(io); int digits{static_cast((bytes * 8) / LOG2_BASE)}; int get{static_cast(bytes * 8) - digits * LOG2_BASE}; if (get > 0) { @@ -100,6 +109,7 @@ template bool EditIntegerOutput(IoStatementState &io, const DataEdit &edit, common::HostSignedIntType<8 * KIND> n) { + addSpaceBeforeCharacter(io); char buffer[130], *end{&buffer[sizeof buffer]}, *p{end}; bool isNegative{n < 0}; using Unsigned = common::HostUnsignedIntType<8 * KIND>; @@ -255,6 +265,7 @@ // 13.7.2.3.3 in F'2018 template bool RealOutputEditing::EditEorDOutput(const DataEdit &edit) { + addSpaceBeforeCharacter(io_); int editDigits{edit.digits.value_or(0)}; // 'd' field int editWidth{edit.width.value_or(0)}; // 'w' field int significantDigits{editDigits}; @@ -381,6 +392,7 @@ // 13.7.2.3.2 in F'2018 template bool RealOutputEditing::EditFOutput(const DataEdit &edit) { + addSpaceBeforeCharacter(io_); int fracDigits{edit.digits.value_or(0)}; // 'd' field const int editWidth{edit.width.value_or(0)}; // 'w' field enum decimal::FortranRounding rounding{edit.modes.round};