[cfe-commits] r66375 - in /cfe/trunk: lib/Lex/ScratchBuffer.cpp test/Misc/caret-diags.c
Chris Lattner
sabre at nondot.org
Sun Mar 8 00:16:41 PST 2009
Author: lattner
Date: Sun Mar 8 03:16:41 2009
New Revision: 66375
URL: http://llvm.org/viewvc/llvm-project?rev=66375&view=rev
Log:
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.
Added:
cfe/trunk/test/Misc/caret-diags.c
Modified:
cfe/trunk/lib/Lex/ScratchBuffer.cpp
Modified: cfe/trunk/lib/Lex/ScratchBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ScratchBuffer.cpp?rev=66375&r1=66374&r2=66375&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ScratchBuffer.cpp (original)
+++ cfe/trunk/lib/Lex/ScratchBuffer.cpp Sun Mar 8 03:16:41 2009
@@ -32,8 +32,12 @@
/// 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 @@
// 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 =
Added: cfe/trunk/test/Misc/caret-diags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/caret-diags.c?rev=66375&view=auto
==============================================================================
--- cfe/trunk/test/Misc/caret-diags.c (added)
+++ cfe/trunk/test/Misc/caret-diags.c Sun Mar 8 03:16:41 2009
@@ -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);
+}
+
More information about the cfe-commits
mailing list