File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -127,12 +127,19 @@ bool SourceFile::ReadStandardInput(llvm::raw_ostream &error) {
127
127
}
128
128
129
129
void SourceFile::ReadFile () {
130
- if (buf_->getBuffer ().size () == 0 ) {
131
- Close ();
132
- buf_ = llvm::WritableMemoryBuffer::getNewUninitMemBuffer (1 );
133
- buf_->getBuffer ()[0 ] = ' \n ' ;
134
- }
135
130
buf_end_ = RemoveCarriageReturns (buf_->getBuffer ());
131
+ if (content ().size () == 0 || content ().back () != ' \n ' ) {
132
+ // Don't bother to copy if we have spare memory
133
+ if (content ().size () >= buf_->getBufferSize ()) {
134
+ auto tmp_buf{llvm::WritableMemoryBuffer::getNewUninitMemBuffer (
135
+ content ().size () + 1 )};
136
+ llvm::copy (content (), tmp_buf->getBufferStart ());
137
+ Close ();
138
+ buf_ = std::move (tmp_buf);
139
+ }
140
+ buf_end_++;
141
+ buf_->getBuffer ()[buf_end_ - 1 ] = ' \n ' ;
142
+ }
136
143
IdentifyPayload ();
137
144
RecordLineStarts ();
138
145
}
Original file line number Diff line number Diff line change
1
+ ! RUN: echo -n "end program" > %t.f90
2
+ ! RUN: %f18 -fparse-only %t.f90
3
+ ! RUN: echo -ne "\rend program" > %t.f90
4
+ ! RUN: %f18 -fparse-only %t.f90
You can’t perform that action at this time.
0 commit comments