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
This commit is contained in:
parent
951f0ca104
commit
fb5afbda32
|
@ -35,6 +35,14 @@ SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len,
|
||||||
const char *&DestPtr) {
|
const char *&DestPtr) {
|
||||||
if (BytesUsed+Len+2 > ScratchBufSize)
|
if (BytesUsed+Len+2 > ScratchBufSize)
|
||||||
AllocScratchBuffer(Len+2);
|
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
|
// Prefix the token with a \n, so that it looks like it is the first thing on
|
||||||
// its own virtual line in caret diagnostics.
|
// its own virtual line in caret diagnostics.
|
||||||
|
|
|
@ -232,3 +232,8 @@ void multiple_ranges(int a, int b) {
|
||||||
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()
|
||||||
|
|
Loading…
Reference in New Issue