From 6f5e1cc9f728bac74f436943ed9dab704c426ef5 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Mon, 31 Jul 2017 17:00:55 +0000 Subject: Merging r309503: ------------------------------------------------------------------------ r309503 | rsmith | 2017-07-29 23:31:29 -0700 (Sat, 29 Jul 2017) | 6 lines 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/branches/release_50@309580 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/ScratchBuffer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') 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( + 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. -- cgit v1.2.3