summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2017-07-31 17:00:55 +0000
committerHans Wennborg <hans@hanshq.net>2017-07-31 17:00:55 +0000
commit6f5e1cc9f728bac74f436943ed9dab704c426ef5 (patch)
tree649aca8b3c7b37f6b3f4ee837cb79642fa810a05
parent36c4419a8ff1c6ff223dad5cc42ec220d8d4413e (diff)
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
-rw-r--r--lib/Lex/ScratchBuffer.cpp8
-rw-r--r--test/Misc/caret-diags-multiline.cpp5
2 files changed, 13 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.
diff --git a/test/Misc/caret-diags-multiline.cpp b/test/Misc/caret-diags-multiline.cpp
index 4826d9beaa..90b50ff398 100644
--- a/test/Misc/caret-diags-multiline.cpp
+++ b/test/Misc/caret-diags-multiline.cpp
@@ -232,3 +232,8 @@ void multiple_ranges(int a, int b) {
b
);
}
+
+#define pr33902_a(b) #b
+#define pr33902_c(d) _Pragma(pr33902_a(d))
+#define pr33902_e(f) pr33902_c(GCC warning #f)
+pr33902_e() pr33902_e()