[flang] Don't blank-fill remaining lines in internal output
Internal writes to character arrays should not blank-fill records (elements) past the last one that was written to. Differential Revision: https://reviews.llvm.org/D117342
This commit is contained in:
parent
533fbae8d8
commit
b77fd01a8f
|
@ -38,15 +38,9 @@ InternalDescriptorUnit<DIR>::InternalDescriptorUnit(
|
|||
}
|
||||
|
||||
template <Direction DIR> void InternalDescriptorUnit<DIR>::EndIoStatement() {
|
||||
if constexpr (DIR == Direction::Output) { // blank fill
|
||||
while (char *record{CurrentRecord()}) {
|
||||
if (furthestPositionInRecord <
|
||||
recordLength.value_or(furthestPositionInRecord)) {
|
||||
std::fill_n(record + furthestPositionInRecord,
|
||||
*recordLength - furthestPositionInRecord, ' ');
|
||||
}
|
||||
furthestPositionInRecord = 0;
|
||||
++currentRecordNumber;
|
||||
if constexpr (DIR == Direction::Output) {
|
||||
if (furthestPositionInRecord > 0) {
|
||||
BlankFillOutputRecord();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,20 +121,26 @@ bool InternalDescriptorUnit<DIR>::AdvanceRecord(IoErrorHandler &handler) {
|
|||
handler.SignalEnd();
|
||||
return false;
|
||||
}
|
||||
if constexpr (DIR == Direction::Output) { // blank fill
|
||||
if (furthestPositionInRecord <
|
||||
recordLength.value_or(furthestPositionInRecord)) {
|
||||
char *record{CurrentRecord()};
|
||||
RUNTIME_CHECK(handler, record != nullptr);
|
||||
std::fill_n(record + furthestPositionInRecord,
|
||||
*recordLength - furthestPositionInRecord, ' ');
|
||||
}
|
||||
if constexpr (DIR == Direction::Output) {
|
||||
BlankFillOutputRecord();
|
||||
}
|
||||
++currentRecordNumber;
|
||||
BeginRecord();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <Direction DIR>
|
||||
void InternalDescriptorUnit<DIR>::BlankFillOutputRecord() {
|
||||
if constexpr (DIR == Direction::Output) {
|
||||
if (furthestPositionInRecord <
|
||||
recordLength.value_or(furthestPositionInRecord)) {
|
||||
char *record{CurrentRecord()};
|
||||
std::fill_n(record + furthestPositionInRecord,
|
||||
*recordLength - furthestPositionInRecord, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <Direction DIR>
|
||||
void InternalDescriptorUnit<DIR>::BackspaceRecord(IoErrorHandler &handler) {
|
||||
RUNTIME_CHECK(handler, currentRecordNumber > 1);
|
||||
|
|
|
@ -45,6 +45,8 @@ private:
|
|||
return descriptor().template ZeroBasedIndexedElement<char>(
|
||||
currentRecordNumber - 1);
|
||||
}
|
||||
void BlankFillOutputRecord();
|
||||
|
||||
StaticDescriptor<maxRank, true /*addendum*/> staticDescriptor_;
|
||||
};
|
||||
|
||||
|
|
|
@ -118,6 +118,9 @@ TEST(IOApiTests, MultilineOutputTest) {
|
|||
auto cookie{IONAME(BeginInternalArrayFormattedOutput)(
|
||||
section, format, std::strlen(format))};
|
||||
|
||||
// Fill last line with periods
|
||||
std::memset(buffer[numLines - 1], '.', lineLength);
|
||||
|
||||
// Write data to buffer
|
||||
IONAME(OutputAscii)(cookie, "WORLD", 5);
|
||||
IONAME(OutputAscii)(cookie, "HELLO", 5);
|
||||
|
@ -135,7 +138,7 @@ TEST(IOApiTests, MultilineOutputTest) {
|
|||
" "
|
||||
"789 abcd 666 777"
|
||||
" 888 999 "
|
||||
" "};
|
||||
"................................"};
|
||||
// Ensure formatted string matches expected output
|
||||
EXPECT_TRUE(
|
||||
CompareFormattedStrings(expect, std::string{buffer[0], sizeof buffer}))
|
||||
|
|
Loading…
Reference in a new issue