forked from OSchip/llvm-project
[flang] Fix handling of files without terminating newlines.
Reviewers: sscalpone Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78578
This commit is contained in:
parent
9f1e81f1c0
commit
b547e1a4d1
|
@ -127,12 +127,19 @@ bool SourceFile::ReadStandardInput(llvm::raw_ostream &error) {
|
|||
}
|
||||
|
||||
void SourceFile::ReadFile() {
|
||||
if (buf_->getBuffer().size() == 0) {
|
||||
Close();
|
||||
buf_ = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(1);
|
||||
buf_->getBuffer()[0] = '\n';
|
||||
}
|
||||
buf_end_ = RemoveCarriageReturns(buf_->getBuffer());
|
||||
if (content().size() == 0 || content().back() != '\n') {
|
||||
// Don't bother to copy if we have spare memory
|
||||
if (content().size() >= buf_->getBufferSize()) {
|
||||
auto tmp_buf{llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
|
||||
content().size() + 1)};
|
||||
llvm::copy(content(), tmp_buf->getBufferStart());
|
||||
Close();
|
||||
buf_ = std::move(tmp_buf);
|
||||
}
|
||||
buf_end_++;
|
||||
buf_->getBuffer()[buf_end_ - 1] = '\n';
|
||||
}
|
||||
IdentifyPayload();
|
||||
RecordLineStarts();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
! RUN: echo -n "end program" > %t.f90
|
||||
! RUN: %f18 -fparse-only %t.f90
|
||||
! RUN: echo -ne "\rend program" > %t.f90
|
||||
! RUN: %f18 -fparse-only %t.f90
|
Loading…
Reference in New Issue