diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-08 08:16:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-08 08:16:41 +0000 |
commit | 2bc69bdb29c4912e90bd213608bd98e1fc73707a (patch) | |
tree | da1c9f12e7125304e3b412bd579da85115e72c05 | |
parent | cd1148b6145094ae3cabd02e6ef1d50dcc2d07b0 (diff) |
add \n characters to the scratch buffer *before* returned tokens.
This prevents caret diagnostics from the scratch buffer from
including other tokens in the scratch buffer that occurred beforei
them.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66375 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Lex/ScratchBuffer.cpp | 10 | ||||
-rw-r--r-- | test/Misc/caret-diags.c | 12 |
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/Lex/ScratchBuffer.cpp b/lib/Lex/ScratchBuffer.cpp index c73cd68a4c..28f3d7ff45 100644 --- a/lib/Lex/ScratchBuffer.cpp +++ b/lib/Lex/ScratchBuffer.cpp @@ -32,8 +32,12 @@ ScratchBuffer::ScratchBuffer(SourceManager &SM) : SourceMgr(SM), CurBuffer(0) { /// token. SourceLocation ScratchBuffer::getToken(const char *Buf, unsigned Len, const char *&DestPtr) { - if (BytesUsed+Len+1 > ScratchBufSize) - AllocScratchBuffer(Len); + if (BytesUsed+Len+2 > ScratchBufSize) + AllocScratchBuffer(Len+2); + + // Prefix the token with a \n, so that it looks like it is the first thing on + // its own virtual line in caret diagnostics. + CurBuffer[BytesUsed++] = '\n'; // Return a pointer to the character data. DestPtr = CurBuffer+BytesUsed; @@ -56,7 +60,7 @@ void ScratchBuffer::AllocScratchBuffer(unsigned RequestLen) { // Only pay attention to the requested length if it is larger than our default // page size. If it is, we allocate an entire chunk for it. This is to // support gigantic tokens, which almost certainly won't happen. :) - if (RequestLen+1 < ScratchBufSize) + if (RequestLen < ScratchBufSize) RequestLen = ScratchBufSize; llvm::MemoryBuffer *Buf = diff --git a/test/Misc/caret-diags.c b/test/Misc/caret-diags.c new file mode 100644 index 0000000000..e6ec03a5b4 --- /dev/null +++ b/test/Misc/caret-diags.c @@ -0,0 +1,12 @@ +// RUN: clang -fsyntax-only %s 2>&1 | not grep keyXXXX +// This should not show keyXXXX in the caret diag output. This once +// happened because the two tokens ended up in the scratch buffer and +// the caret diag from the scratch buffer included the previous token. +#define M(name) \ + if (name ## XXXX != name ## _sb); + +void foo() { + int keyXXXX; + M(key); +} + |