diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MC/MCAsmStreamer.cpp | 7 | ||||
-rw-r--r-- | lib/Support/raw_ostream.cpp | 13 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index e284e15bca..d4ef3ca826 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -136,6 +136,9 @@ void MCAsmStreamer::AddComment(const Twine &T) { T.toVector(CommentToEmit); // Each comment goes on its own line. CommentToEmit.push_back('\n'); + + // Tell the comment stream that the vector changed underneath it. + CommentStream.resync(); } void MCAsmStreamer::EmitCommentsAndEOL() { @@ -158,7 +161,9 @@ void MCAsmStreamer::EmitCommentsAndEOL() { Comments = Comments.substr(Position+1); } while (!Comments.empty()); - CommentStream.clear(); + CommentToEmit.clear(); + // Tell the comment stream that the vector changed underneath it. + CommentStream.resync(); } diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 7cd16c888b..10d7ec0701 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -562,11 +562,14 @@ raw_svector_ostream::~raw_svector_ostream() { flush(); } -/// clear - Flush the stream and clear the underlying vector. -void raw_svector_ostream::clear() { - if (GetNumBytesInBuffer() == 0) flush(); - - OS.clear(); +/// resync - This is called when the SmallVector we're appending to is changed +/// outside of the raw_svector_ostream's control. It is only safe to do this +/// if the raw_svector_ostream has previously been flushed. +void raw_svector_ostream::resync() { + assert(GetNumBytesInBuffer() == 0 && "Didn't flush before mutating vector"); + + if (OS.capacity() - OS.size() < 64) + OS.reserve(OS.capacity() * 2); SetBuffer(OS.end(), OS.capacity() - OS.size()); } |