diff --git a/flang-rt/include/flang-rt/runtime/connection.h b/flang-rt/include/flang-rt/runtime/connection.h index 158e156d1b0b3..3e783af1fa748 100644 --- a/flang-rt/include/flang-rt/runtime/connection.h +++ b/flang-rt/include/flang-rt/runtime/connection.h @@ -66,6 +66,14 @@ struct ConnectionState : public ConnectionAttributes { RT_API_ATTRS bool NeedAdvance(std::size_t width) const { return positionInRecord > 0 && width > RemainingSpaceInRecord(); } + RT_API_ATTRS bool NeedHardAdvance(std::size_t width) const { + auto recl{recordLength}; + if (!recl) { + recl = openRecl; + } + return recl && positionInRecord > 0 && + static_cast(positionInRecord + width) > *recl; + } RT_API_ATTRS void HandleAbsolutePosition(std::int64_t n) { positionInRecord = (n < 0 ? 0 : n) + leftTabLimit.value_or(0); } diff --git a/flang-rt/include/flang-rt/runtime/format-implementation.h b/flang-rt/include/flang-rt/runtime/format-implementation.h index 46134146f5c13..d510adbb5ba46 100644 --- a/flang-rt/include/flang-rt/runtime/format-implementation.h +++ b/flang-rt/include/flang-rt/runtime/format-implementation.h @@ -430,6 +430,9 @@ RT_API_ATTRS int FormatControl::CueUpNextDataEdit( if constexpr (std::is_base_of_v) { context.HandleRelativePosition(chars); } else { + if (context.GetConnectionState().NeedHardAdvance(chars)) { + context.AdvanceRecord(); + } EmitAscii(context, format_ + start, chars); } } else if (ch == 'H') { @@ -442,6 +445,9 @@ RT_API_ATTRS int FormatControl::CueUpNextDataEdit( if constexpr (std::is_base_of_v) { context.HandleRelativePosition(static_cast(*repeat)); } else { + if (context.GetConnectionState().NeedHardAdvance(*repeat)) { + context.AdvanceRecord(); + } EmitAscii( context, format_ + offset_, static_cast(*repeat)); } @@ -487,6 +493,9 @@ RT_API_ATTRS int FormatControl::CueUpNextDataEdit( } else if (ch == '\t' || ch == '\v') { // Tabs (extension) // TODO: any other raw characters? + if (context.GetConnectionState().NeedHardAdvance(1)) { + context.AdvanceRecord(); + } EmitAscii(context, format_ + offset_ - 1, 1); } else { ReportBadFormat( diff --git a/flang-rt/include/flang-rt/runtime/io-error.h b/flang-rt/include/flang-rt/runtime/io-error.h index 0ac1183131808..d2180a83f8c3c 100644 --- a/flang-rt/include/flang-rt/runtime/io-error.h +++ b/flang-rt/include/flang-rt/runtime/io-error.h @@ -15,9 +15,9 @@ #ifndef FLANG_RT_RUNTIME_IO_ERROR_H_ #define FLANG_RT_RUNTIME_IO_ERROR_H_ +#include "iostat.h" #include "memory.h" #include "terminator.h" -#include "flang/Runtime/iostat.h" #include namespace Fortran::runtime::io { diff --git a/flang/include/flang/Runtime/iostat.h b/flang-rt/include/flang-rt/runtime/iostat.h similarity index 91% rename from flang/include/flang/Runtime/iostat.h rename to flang-rt/include/flang-rt/runtime/iostat.h index d8db68a3a1c2e..44ddd0e72feef 100644 --- a/flang/include/flang/Runtime/iostat.h +++ b/flang-rt/include/flang-rt/runtime/iostat.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/iostat.h --------------------------*- C++ -*-===// +//===-- include/flang-rt/runtime/iostat.h -----------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. diff --git a/flang-rt/lib/runtime/iostat.cpp b/flang-rt/lib/runtime/iostat.cpp index 0f8bfb884e544..c2577e7caf0e1 100644 --- a/flang-rt/lib/runtime/iostat.cpp +++ b/flang-rt/lib/runtime/iostat.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/iostat.h" +#include "flang-rt/runtime/iostat.h" namespace Fortran::runtime::io { RT_OFFLOAD_API_GROUP_BEGIN diff --git a/flang/include/flang/Runtime/iostat-consts.h b/flang/include/flang/Runtime/iostat-consts.h index 26bf75f59fa0d..47093d971bf77 100644 --- a/flang/include/flang/Runtime/iostat-consts.h +++ b/flang/include/flang/Runtime/iostat-consts.h @@ -9,7 +9,6 @@ #ifndef FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ #define FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ -#include "flang/Common/api-attrs.h" #include "flang/Runtime/magic-numbers.h" namespace Fortran::runtime::io {