summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-07-30 06:31:29 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-07-30 06:31:29 +0000
commitfb5afbda32121efcea85102b2727ce9017411390 (patch)
tree040a89cccb97fc74f5457c0c8210a98930bdc98e
parent951f0ca1043376b596bd39508eb17208f993b7cc (diff)
downloadbcm5719-llvm-fb5afbda32121efcea85102b2727ce9017411390.tar.gz
bcm5719-llvm-fb5afbda32121efcea85102b2727ce9017411390.zip
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. llvm-svn: 309503
-rw-r--r--clang/lib/Lex/ScratchBuffer.cpp8
-rw-r--r--clang/test/Misc/caret-diags-multiline.cpp5
2 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Lex/ScratchBuffer.cpp b/clang/lib/Lex/ScratchBuffer.cpp
index cd8a27e76c2..e0f3966fce4 100644
--- a/clang/lib/Lex/ScratchBuffer.cpp
+++ b/clang/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/clang/test/Misc/caret-diags-multiline.cpp b/clang/test/Misc/caret-diags-multiline.cpp
index 4826d9beaa3..90b50ff398a 100644
--- a/clang/test/Misc/caret-diags-multiline.cpp
+++ b/clang/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()
OpenPOWER on IntegriCloud