diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-07-30 06:31:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-07-30 06:31:29 +0000 |
commit | f29d44a306f1ad20d1b2bf82ccbd6b7848786909 (patch) | |
tree | 33230e108c987dec8a7a126b2609481cf3cbbd9e /lib/Lex/ScratchBuffer.cpp | |
parent | 0adbc97362f090b05f50b1438de7b2dd724a4af0 (diff) | |
download | clang-f29d44a306f1ad20d1b2bf82ccbd6b7848786909.tar.gz |
PR33902: Invalidate line number cache when adding more text to existing buffer.
This led to crashes as the line number cache would report a bogus line number
for a line of code, and we'd try to find a nonexistent column within the line
when printing diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309503 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/ScratchBuffer.cpp')
-rw-r--r-- | lib/Lex/ScratchBuffer.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Lex/ScratchBuffer.cpp b/lib/Lex/ScratchBuffer.cpp index cd8a27e76c..e0f3966fce 100644 --- a/lib/Lex/ScratchBuffer.cpp +++ b/lib/Lex/ScratchBuffer.cpp @@ -35,6 +35,14 @@ SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len, const char *&DestPtr) { if (BytesUsed+Len+2 > ScratchBufSize) AllocScratchBuffer(Len+2); + else { + // Clear out the source line cache if it's already been computed. + // FIXME: Allow this to be incrementally extended. + auto *ContentCache = const_cast<SrcMgr::ContentCache *>( + SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc)) + .getFile().getContentCache()); + ContentCache->SourceLineCache = nullptr; + } // Prefix the token with a \n, so that it looks like it is the first thing on // its own virtual line in caret diagnostics. |